Skip to content

Commit

Permalink
Merge pull request #65 from paulfioravanti/fixes
Browse files Browse the repository at this point in the history
Extract out some case type modules
  • Loading branch information
paulfioravanti committed Mar 22, 2017
2 parents fdfd440 + c7ec7ea commit f2af802
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ RSpec/MultipleExpectations:
RSpec/NestedGroups:
Max: 8

Style/CaseEquality:
# NOTE: This is rule is disabled, but care should be made to
# *only ever* use `===` in `case` statements.
Enabled: false

Style/Documentation:
Enabled: false

Expand Down
11 changes: 11 additions & 0 deletions lib/resume/cli/align_key.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Resume
module CLI
module AlignKey
module_function

def ===(other)
other.first == :align
end
end
end
end
10 changes: 7 additions & 3 deletions lib/resume/cli/content_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
require "base64"
require_relative "file_fetcher"
require_relative "file_system"
require_relative "align_key"
require_relative "font_hash"
require_relative "styles_array"

module Resume
module CLI
Expand Down Expand Up @@ -60,15 +63,16 @@ def parse_hash(hash)
private_class_method :parse_hash

def munge_hash_value(hash, key, value)
if key == :align
case [key, value]
when AlignKey
# Prawn specifically requires :align values to
# be symbols otherwise it errors out
hash[key] = value.to_sym
elsif key == :styles && value.is_a?(Array)
when StylesArray
# Prawn specifically requires :styles values to
# be symbols otherwise the styles do not take effect
hash[key] = value.map!(&:to_sym)
elsif key == :font && value.is_a?(Hash)
when 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
11 changes: 11 additions & 0 deletions lib/resume/cli/font_hash.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Resume
module CLI
module FontHash
module_function

def ===(other)
other.first == :font && other.last.is_a?(Hash)
end
end
end
end
11 changes: 11 additions & 0 deletions lib/resume/cli/styles_array.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Resume
module CLI
module StylesArray
module_function

def ===(other)
other.first == :styles && other.last.is_a?(Array)
end
end
end
end
20 changes: 19 additions & 1 deletion lib/tasks/one_sheet/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,17 @@
- :file: file_fetcher.rb
:from_line: 9
:to_line: -3
- :file: align_key.rb
:from_line: 2
:to_line: -3
- :file: font_hash.rb
:from_line: 2
:to_line: -3
- :file: styles_array.rb
:from_line: 2
:to_line: -3
- :file: content_parser.rb
:from_line: 7
:from_line: 10
:to_line: -3
- :file: settings.rb
:from_line: 6
Expand Down Expand Up @@ -139,6 +148,15 @@
- :file: application_spec.rb
:from_line: 4
:to_line: -3
- :file: align_key_spec.rb
:from_line: 4
:to_line: -3
- :file: font_hash_spec.rb
:from_line: 4
:to_line: -3
- :file: styles_array_spec.rb
:from_line: 4
:to_line: -3
- :file: argument_parser_spec.rb
:from_line: 5
:to_line: -3
Expand Down
25 changes: 25 additions & 0 deletions spec/lib/resume/cli/align_key_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "resume/cli/align_key"

module Resume
module CLI
RSpec.describe AlignKey do
describe ".===" do
context "when other has an align key" do
let(:align_key) { [:align, 1] }

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

context "when other does not have an align key" do
let(:non_align_key) { [:something_else, 1] }

it "returns false" do
expect(described_class === non_align_key).to be false
end
end
end
end
end
end
33 changes: 33 additions & 0 deletions spec/lib/resume/cli/font_hash_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "resume/cli/font_hash"

module Resume
module CLI
RSpec.describe FontHash do
describe ".===" do
context "when other has a font key with a Hash of values" do
let(:font_hash) { [:font, { foo: "bar" }] }

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

context "when other has a non-font key with a Hash of values" do
let(:non_font_hash) { [:something_else, { foo: "bar" }] }

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

context "when other has a font key but not a Hash of values" do
let(:non_font_hash) { [:font, [1, 2, 3]] }

it "returns false" do
expect(described_class === non_font_hash).to be false
end
end
end
end
end
end
33 changes: 33 additions & 0 deletions spec/lib/resume/cli/styles_array_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require "resume/cli/styles_array"

module Resume
module CLI
RSpec.describe StylesArray do
describe ".===" do
context "when other has a styles key with an Array of values" do
let(:styles_array) { [:styles, [1, 2, 3]] }

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

context "when other has a non-styles key with an Array of values" do
let(:non_styles_array) { [:something_else, [1, 2, 3]] }

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

context "when other has a styles key but not an Array of values" do
let(:non_styles_array) { [:styles, { foo: "bar" }] }

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

0 comments on commit f2af802

Please sign in to comment.