Class: Hulse::Record
- Inherits:
-
Object
- Object
- Hulse::Record
- Defined in:
- lib/hulse/record.rb
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#section ⇒ Object
readonly
Returns the value of attribute section.
-
#topics ⇒ Object
readonly
Returns the value of attribute topics.
Class Method Summary collapse
- .base_url(date = nil) ⇒ Object
- .create_from_html(html, date, section) ⇒ Object
- .daily_digest(date = nil) ⇒ Object
- .extension_of_remarks(date = nil) ⇒ Object
- .house(date = nil) ⇒ Object
- .senate(date = nil) ⇒ Object
- .topics(html) ⇒ Object
Instance Method Summary collapse
- #chairman_designations ⇒ Object
- #committee_elections ⇒ Object
- #committee_leaves_of_absence ⇒ Object
- #has_committee_elections? ⇒ Boolean
- #has_committee_resignations? ⇒ Boolean
- #has_personal_explanations? ⇒ Boolean
- #has_senate_explanations? ⇒ Boolean
-
#initialize(params = {}) ⇒ Record
constructor
A new instance of Record.
- #leaves_of_absence ⇒ Object
- #personal_explanations ⇒ Object
- #ranking_designations ⇒ Object
- #senate_explanations ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Record
Returns a new instance of Record.
6 7 8 9 10 |
# File 'lib/hulse/record.rb', line 6 def initialize(params={}) params.each_pair do |k,v| instance_variable_set("@#{k}", v) end end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/hulse/record.rb', line 4 def date @date end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
4 5 6 |
# File 'lib/hulse/record.rb', line 4 def html @html end |
#section ⇒ Object (readonly)
Returns the value of attribute section.
4 5 6 |
# File 'lib/hulse/record.rb', line 4 def section @section end |
#topics ⇒ Object (readonly)
Returns the value of attribute topics.
4 5 6 |
# File 'lib/hulse/record.rb', line 4 def topics @topics end |
Class Method Details
.base_url(date = nil) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/hulse/record.rb', line 16 def self.base_url(date=nil) if date year, month, day = date.year, date.month, date.day else date = Date.today-1 year, month, day = date.year, date.month, date.day end "https://www.congress.gov/congressional-record/#{year}/#{month}/#{day}/" end |
.create_from_html(html, date, section) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/hulse/record.rb', line 47 def self.create_from_html(html, date, section) section_topics = topics(html) self.new(date: date, section: section, topics: section_topics, html: html ) end |
.daily_digest(date = nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/hulse/record.rb', line 26 def self.daily_digest(date=nil) doc = HTTParty.get(base_url(date)+'daily-digest') html = Nokogiri::HTML(doc.parsed_response) (html/:pre).text end |
.extension_of_remarks(date = nil) ⇒ Object
42 43 44 45 |
# File 'lib/hulse/record.rb', line 42 def self.extension_of_remarks(date=nil) doc = HTTParty.get(base_url(date)+'extensions-of-remarks-section') create_from_html(Nokogiri::HTML(doc.parsed_response), date, 'extension') end |
.house(date = nil) ⇒ Object
37 38 39 40 |
# File 'lib/hulse/record.rb', line 37 def self.house(date=nil) doc = HTTParty.get(base_url(date)+'house-section') create_from_html(Nokogiri::HTML(doc.parsed_response), date, 'house') end |
.senate(date = nil) ⇒ Object
32 33 34 35 |
# File 'lib/hulse/record.rb', line 32 def self.senate(date=nil) doc = HTTParty.get(base_url(date)+'senate-section') create_from_html(Nokogiri::HTML(doc.parsed_response), date, 'senate') end |
.topics(html) ⇒ Object
56 57 58 |
# File 'lib/hulse/record.rb', line 56 def self.topics(html) (html/:td).map{|d| d.children[1]}.compact.map{|l| {url: l['href'], title: l.text.strip}} end |
Instance Method Details
#chairman_designations ⇒ Object
88 89 90 |
# File 'lib/hulse/record.rb', line 88 def chairman_designations topics.select{|l| l[:title].include?("DESIGNATING THE CHAIRMAN")} end |
#committee_elections ⇒ Object
80 81 82 |
# File 'lib/hulse/record.rb', line 80 def committee_elections topics.select{|l| l[:title].include?("COMMITTEE ELECTION")} end |
#committee_leaves_of_absence ⇒ Object
100 101 102 |
# File 'lib/hulse/record.rb', line 100 def committee_leaves_of_absence topics.select{|l| l[:title].include?("COMMITTEE LEAVE OF ABSENCE")} end |
#has_committee_elections? ⇒ Boolean
76 77 78 |
# File 'lib/hulse/record.rb', line 76 def has_committee_elections? topics.select{|l| l[:title].include?("COMMITTEE ELECTION")}.empty? ? false : true end |
#has_committee_resignations? ⇒ Boolean
84 85 86 |
# File 'lib/hulse/record.rb', line 84 def has_committee_resignations? topics.select{|l| l[:title].include?("COMMITTEE RESIGNATION")}.empty? ? false : true end |
#has_personal_explanations? ⇒ Boolean
68 69 70 |
# File 'lib/hulse/record.rb', line 68 def has_personal_explanations? topics.select{|l| l[:title].include?("PERSONAL EXPLANATION")}.empty? ? false : true end |
#has_senate_explanations? ⇒ Boolean
60 61 62 |
# File 'lib/hulse/record.rb', line 60 def has_senate_explanations? topics.select{|l| l[:title].include?("VOTE EXPLANATION")}.empty? ? false : true end |
#leaves_of_absence ⇒ Object
96 97 98 |
# File 'lib/hulse/record.rb', line 96 def leaves_of_absence topics.select{|l| l[:title].include?("LEAVE OF ABSENCE")} end |
#personal_explanations ⇒ Object
72 73 74 |
# File 'lib/hulse/record.rb', line 72 def personal_explanations topics.select{|l| l[:title].include?("PERSONAL EXPLANATION")} end |
#ranking_designations ⇒ Object
92 93 94 |
# File 'lib/hulse/record.rb', line 92 def ranking_designations topics.select{|l| l[:title].include?("DESIGNATING THE RANKING")} end |
#senate_explanations ⇒ Object
64 65 66 |
# File 'lib/hulse/record.rb', line 64 def senate_explanations topics.select{|l| l[:title].include?("VOTE EXPLANATION")} end |
#to_s ⇒ Object
12 13 14 |
# File 'lib/hulse/record.rb', line 12 def to_s section end |