Class: SoFarSoGood::Subpart

Inherits:
Object
  • Object
show all
Defined in:
lib/so_far_so_good/subpart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#chapterObject (readonly)

Returns the value of attribute chapter.



8
9
10
# File 'lib/so_far_so_good/subpart.rb', line 8

def chapter
  @chapter
end

#nodeObject (readonly)

Returns the value of attribute node.



4
5
6
# File 'lib/so_far_so_good/subpart.rb', line 4

def node
  @node
end

#subchapterObject (readonly)

Returns the value of attribute subchapter.



9
10
11
# File 'lib/so_far_so_good/subpart.rb', line 9

def subchapter
  @subchapter
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/so_far_so_good/subpart.rb', line 6

def title
  @title
end

#volumeObject (readonly)

Returns the value of attribute volume.



7
8
9
# File 'lib/so_far_so_good/subpart.rb', line 7

def volume
  @volume
end

#yearObject (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(options = {})
  options = {:format => :html}.merge(options)
  @body ||= node.css("> P").to_html
  if options[:format] == :markdown
    ReverseMarkdown.convert @body, :unknown_tags => :bypass
  else
    @body
  end
end

#citationObject



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(options = {})
  options = {:format => :html}.merge(options)
  @extract ||= node.css("EXTRACT").inner_html
  if options[:format] == :markdown
    ReverseMarkdown.convert @extract, :unknown_tags => :bypass
  else
    @extract
  end
end

#inspectObject



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


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

#numberObject



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

Returns:

  • (Boolean)


29
30
31
# File 'lib/so_far_so_good/subpart.rb', line 29

def reserved?
  @reserved ||= !node.css("RESERVED").text.empty? || subject == "[Reserved]"
end

#subjectObject



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(options={})
  {
    :year        => year,
    :title       => title,
    :volume      => volume,
    :chapter     => chapter,
    :number      => number,
    :subject     => subject,
    :reserverd   => reserved,
    :citation    => citation,
    :extract     => extract(options),
    :body        => body(options),
    :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(options = {})
  to_hash(options).to_json(options)
end