Class: SoFarSoGood::Subchapter
- Inherits:
-
Object
- Object
- SoFarSoGood::Subchapter
- Defined in:
- lib/so_far_so_good/subchapter.rb
Instance Attribute Summary collapse
-
#chapter ⇒ Object
readonly
Returns the value of attribute chapter.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #[](number) ⇒ Object
-
#initialize(hash) ⇒ Subchapter
constructor
A new instance of Subchapter.
- #inspect ⇒ Object
- #numbers(options = {}) ⇒ Object
- #subjects(options = {}) ⇒ Object
- #subparts(options = {}) ⇒ Object
- #to_csv(options = {}) ⇒ Object
- #to_hash ⇒ Object
- #to_json(options = {}) ⇒ Object
- #to_md(options = {}) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Subchapter
Returns a new instance of Subchapter.
10 11 12 13 14 15 16 |
# File 'lib/so_far_so_good/subchapter.rb', line 10 def initialize(hash) @volume = hash[:volume] @chapter = hash[:chapter] @name = hash[:name] @year = SoFarSoGood::YEAR @title = SoFarSoGood::TITLE end |
Instance Attribute Details
#chapter ⇒ Object (readonly)
Returns the value of attribute chapter.
7 8 9 |
# File 'lib/so_far_so_good/subchapter.rb', line 7 def chapter @chapter end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/so_far_so_good/subchapter.rb', line 8 def name @name end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/so_far_so_good/subchapter.rb', line 5 def title @title end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
6 7 8 |
# File 'lib/so_far_so_good/subchapter.rb', line 6 def volume @volume end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
4 5 6 |
# File 'lib/so_far_so_good/subchapter.rb', line 4 def year @year end |
Instance Method Details
#[](number) ⇒ Object
60 61 62 |
# File 'lib/so_far_so_good/subchapter.rb', line 60 def [](number) subparts.find { |s| s.number == number } end |
#inspect ⇒ Object
64 65 66 |
# File 'lib/so_far_so_good/subchapter.rb', line 64 def inspect "#<SoFarSoGood::Subchapter year=#{year} title=#{title} volume=#{volume} chapter=#{chapter} name=\"#{name}\">" end |
#numbers(options = {}) ⇒ Object
18 19 20 |
# File 'lib/so_far_so_good/subchapter.rb', line 18 def numbers( = {}) @numbers ||= subparts().map { |s| s.number } end |
#subjects(options = {}) ⇒ Object
22 23 24 |
# File 'lib/so_far_so_good/subchapter.rb', line 22 def subjects( = {}) @subjects ||= subparts().map { |s| s.subject } end |
#subparts(options = {}) ⇒ Object
26 27 28 29 |
# File 'lib/so_far_so_good/subchapter.rb', line 26 def subparts( = {}) @subparts ||= sections.map { |node| SoFarSoGood::Subpart.new(to_hash.merge(:node => node)) } @subparts.select { |subpart| .all? { |k,v| subpart.send(k) == v } } end |
#to_csv(options = {}) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/so_far_so_good/subchapter.rb', line 41 def to_csv( = {}) CSV.generate do |csv| csv << HEADINGS subparts().each do |c| csv << [c.number , c.subject] end end end |
#to_hash ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/so_far_so_good/subchapter.rb', line 50 def to_hash { :year => year, :title => title, :volume => volume, :chapter => chapter, :name => name } end |
#to_json(options = {}) ⇒ Object
37 38 39 |
# File 'lib/so_far_so_good/subchapter.rb', line 37 def to_json( = {}) subparts().to_json() end |
#to_md(options = {}) ⇒ Object
31 32 33 34 35 |
# File 'lib/so_far_so_good/subchapter.rb', line 31 def to_md( = {}) links = .delete(:links) == true rows = subparts().map { |c| [ links ? "[#{c.number}](#{c.link})" : c.number , c.subject] } Terminal::Table.new(:rows => rows, :style => { :border_i => "|" }, :headings => HEADINGS).to_s end |