Skip to content

Commit

Permalink
Unify all the resume node types used in the parser case statement und…
Browse files Browse the repository at this point in the history
…er one module
  • Loading branch information
paulfioravanti committed Mar 24, 2017
1 parent 8022e6f commit 1b817a4
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 68 deletions.
15 changes: 0 additions & 15 deletions lib/resume/cli/align_key.rb

This file was deleted.

9 changes: 4 additions & 5 deletions lib/resume/cli/content_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
require "base64"
require_relative "file_fetcher"
require_relative "file_system"
require_relative "align_key"
require_relative "collection_of_type"
require_relative "resume_node_types"

module Resume
module CLI
Expand Down Expand Up @@ -63,15 +62,15 @@ def parse_hash(hash)

def munge_hash_value(hash, key, value)
case Hash[key, value]
when AlignKey
when ResumeNodeTypes::AlignValue
# Prawn specifically requires :align values to
# be symbols otherwise it errors out
hash[key] = value.to_sym
when CollectionOfType::StylesArray
when ResumeNodeTypes::StylesArray
# Prawn specifically requires :styles values to
# be symbols otherwise the styles do not take effect
hash[key] = value.map!(&:to_sym)
when CollectionOfType::FontHash
when ResumeNodeTypes::FontHash
# This is the hash that tells Prawn what the fonts to be used
# are called and where they are located
substitute_filenames_for_filepaths(value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
module Resume
module CLI
module CollectionOfType
module ResumeNodeTypes
module_function

def collection_of_type?(hash, key, collection_type)
def key_of_type?(hash, key, collection_type)
return false unless hash.length == 1
hash.key?(key) && hash[key].is_a?(collection_type)
end

module AlignValue
module_function

def ===(other)
Module.nesting[1].key_of_type?(other, :align, String)
end
end

module FontHash
module_function

def ===(other)
Module.nesting[1].collection_of_type?(other, :font, Hash)
Module.nesting[1].key_of_type?(other, :font, Hash)
end
end

module StylesArray
module_function

def ===(other)
Module.nesting[1].collection_of_type?(other, :styles, Array)
Module.nesting[1].key_of_type?(other, :styles, Array)
end
end
end
Expand Down
12 changes: 3 additions & 9 deletions lib/tasks/one_sheet/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,11 @@
- :file: file_fetcher.rb
:from_line: 9
:to_line: -3
- :file: align_key.rb
:from_line: 2
:to_line: -3
- :file: collection_of_type.rb
- :file: resume_node_types.rb
:from_line: 2
:to_line: -3
- :file: content_parser.rb
:from_line: 9
:from_line: 8
:to_line: -3
- :file: settings.rb
:from_line: 6
Expand Down Expand Up @@ -145,10 +142,7 @@
- :file: application_spec.rb
:from_line: 4
:to_line: -3
- :file: align_key_spec.rb
:from_line: 4
:to_line: -3
- :file: collection_of_type_spec.rb
- :file: resume_node_types_spec.rb
:from_line: 4
:to_line: -3
- :file: argument_parser_spec.rb
Expand Down
33 changes: 0 additions & 33 deletions spec/lib/resume/cli/align_key_spec.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
require "resume/cli/collection_of_type"
require "resume/cli/resume_node_types"

module Resume
module CLI
module CollectionOfType
module ResumeNodeTypes
RSpec.describe AlignValue do
describe ".===" do
context "when other has a length > 1" do
let(:long_hash) { { align: 1, extra: 2 } }

it "returns false" do
expect(described_class === long_hash).to be false
end
end

context "when other has length == 1 but key != :align" do
let(:non_align_value) { { something_else: 1 } }

it "returns false" do
expect(described_class === non_align_value).to be false
end
end

context "when other has length == 1 and :align is a String" do
let(:align_value) { { align: "1" } }

it "returns value" do
expect(described_class === align_value).to be true
end
end
end
end

RSpec.describe FontHash do
describe ".===" do
context "when other has a length > 1" do
Expand Down

0 comments on commit 1b817a4

Please sign in to comment.