Class: SoFarSoGood::Subpart
- Inherits:
-
Object
- Object
- SoFarSoGood::Subpart
- Defined in:
- lib/so_far_so_good/subpart.rb
Instance Attribute Summary collapse
-
#chapter ⇒ Object
readonly
Returns the value of attribute chapter.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#subchapter ⇒ Object
readonly
Returns the value of attribute subchapter.
-
#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
- #body(options = {}) ⇒ Object
- #citation ⇒ Object
- #extract(options = {}) ⇒ Object
-
#initialize(hash) ⇒ Subpart
constructor
A new instance of Subpart.
- #inspect ⇒ Object
- #link ⇒ Object
- #number ⇒ Object
- #reserved? ⇒ Boolean (also: #reserved)
- #subject ⇒ Object
- #to_hash(options = {}) ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(hash) ⇒ Subpart
Returns a new instance of Subpart.
11 12 13 14 15 16 17 18 19 |
# File 'lib/so_far_so_good/subpart.rb', line 11 def initialize(hash) @year = hash[:year] @title = hash[:title] @volume = hash[:volume] @chapter = hash[:chapter] @subchapter = hash[:name] @node = hash[:node] normalize! end |
Instance Attribute Details
#chapter ⇒ Object (readonly)
Returns the value of attribute chapter.
8 9 10 |
# File 'lib/so_far_so_good/subpart.rb', line 8 def chapter @chapter end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
4 5 6 |
# File 'lib/so_far_so_good/subpart.rb', line 4 def node @node end |
#subchapter ⇒ Object (readonly)
Returns the value of attribute subchapter.
9 10 11 |
# File 'lib/so_far_so_good/subpart.rb', line 9 def subchapter @subchapter end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
6 7 8 |
# File 'lib/so_far_so_good/subpart.rb', line 6 def title @title end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
7 8 9 |
# File 'lib/so_far_so_good/subpart.rb', line 7 def volume @volume end |
#year ⇒ Object (readonly)
Returns the value of attribute year.
5 6 7 |
# File 'lib/so_far_so_good/subpart.rb', line 5 def year @year end |
Instance Method Details
#body(options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/so_far_so_good/subpart.rb', line 52 def body( = {}) = {:format => :html}.merge() @body ||= node.css("> P").to_html if [:format] == :markdown ReverseMarkdown.convert @body, :unknown_tags => :bypass else @body end end |
#citation ⇒ Object
34 35 36 |
# File 'lib/so_far_so_good/subpart.rb', line 34 def citation @citation ||= node.css("CITA").text.strip end |
#extract(options = {}) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/so_far_so_good/subpart.rb', line 42 def extract( = {}) = {:format => :html}.merge() @extract ||= node.css("EXTRACT").inner_html if [:format] == :markdown ReverseMarkdown.convert @extract, :unknown_tags => :bypass else @extract end end |
#inspect ⇒ Object
83 84 85 |
# File 'lib/so_far_so_good/subpart.rb', line 83 def inspect "#<SoFarSoGood::Subpart year=#{year} title=#{title} volume=#{volume} chapter=#{chapter} number=\"#{number}\" subject=\"#{subject}\" subchapter=\"#{subchapter}\" reserved=#{reserved}>" end |
#link ⇒ Object
38 39 40 |
# File 'lib/so_far_so_good/subpart.rb', line 38 def link @link ||= "http://www.law.cornell.edu/cfr/text/48/#{number}" end |
#number ⇒ Object
21 22 23 |
# File 'lib/so_far_so_good/subpart.rb', line 21 def number @number ||= node.css("SECTNO").text.strip end |
#reserved? ⇒ Boolean Also known as: reserved
29 30 31 |
# File 'lib/so_far_so_good/subpart.rb', line 29 def reserved? @reserved ||= !node.css("RESERVED").text.empty? || subject == "[Reserved]" end |
#subject ⇒ Object
25 26 27 |
# File 'lib/so_far_so_good/subpart.rb', line 25 def subject @subject ||= node.css("SUBJECT, RESERVED").text.strip end |
#to_hash(options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/so_far_so_good/subpart.rb', line 62 def to_hash(={}) { :year => year, :title => title, :volume => volume, :chapter => chapter, :number => number, :subject => subject, :reserverd => reserved, :citation => citation, :extract => extract(), :body => body(), :link => link, :subchapter => subchapter, } end |
#to_json(options = {}) ⇒ Object
79 80 81 |
# File 'lib/so_far_so_good/subpart.rb', line 79 def to_json( = {}) to_hash().to_json() end |