Skip to content

Commit

Permalink
add new methods: Book#catalog=(catalog) and Catalog.new(obj)
Browse files Browse the repository at this point in the history
  • Loading branch information
takahashim committed Mar 5, 2016
1 parent aaaa19c commit 93691d0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/review/book/base.rb
Expand Up @@ -201,6 +201,10 @@ def catalog
@catalog
end

def catalog=(catalog)
@catalog = catalog
end

def read_CHAPS
if catalog
catalog.chaps
Expand Down
6 changes: 5 additions & 1 deletion lib/review/catalog.rb
Expand Up @@ -3,7 +3,11 @@
module ReVIEW
class Catalog
def initialize(file)
@yaml = YAML.load(file.read)
if file.respond_to? :read
@yaml = YAML.load(file.read)
else ## as Object
@yaml = file
end
@yaml ||= {}
end

Expand Down
17 changes: 17 additions & 0 deletions test/test_catalog.rb
Expand Up @@ -81,6 +81,16 @@ def test_postdef
assert_equal(exp.chomp, sut.postdef)
end

def test_from_object
sut = Catalog.new(yaml_hash)
exp =<<-EOS
ch01.re
ch02.re
EOS
assert_equal(exp.chomp, sut.chaps)
end


private
def yaml
StringIO.new <<-EOS
Expand All @@ -103,6 +113,13 @@ def yaml
EOS
end

def yaml_hash
{"PREDEF" => %w(pre01.re pre02.re),
"CHAPS" => %w(ch01.re ch02.re),
"APPENDIX" => %w(post01.re post02.re),
"POSTDEF" => %w(back01.re back02.re)}
end

def yaml_with_parts
StringIO.new <<-EOS
CHAPS:
Expand Down

0 comments on commit 93691d0

Please sign in to comment.