Class: Hulse::Record

Inherits:
Object
  • Object
show all
Defined in:
lib/hulse/record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dateObject (readonly)

Returns the value of attribute date.



4
5
6
# File 'lib/hulse/record.rb', line 4

def date
  @date
end

#htmlObject (readonly)

Returns the value of attribute html.



4
5
6
# File 'lib/hulse/record.rb', line 4

def html
  @html
end

#sectionObject (readonly)

Returns the value of attribute section.



4
5
6
# File 'lib/hulse/record.rb', line 4

def section
  @section
end

#topicsObject (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_designationsObject



88
89
90
# File 'lib/hulse/record.rb', line 88

def chairman_designations
  topics.select{|l| l[:title].include?("DESIGNATING THE CHAIRMAN")}
end

#committee_electionsObject



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_absenceObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_absenceObject



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_explanationsObject



72
73
74
# File 'lib/hulse/record.rb', line 72

def personal_explanations
  topics.select{|l| l[:title].include?("PERSONAL EXPLANATION")}
end

#ranking_designationsObject



92
93
94
# File 'lib/hulse/record.rb', line 92

def ranking_designations
  topics.select{|l| l[:title].include?("DESIGNATING THE RANKING")}
end

#senate_explanationsObject



64
65
66
# File 'lib/hulse/record.rb', line 64

def senate_explanations
  topics.select{|l| l[:title].include?("VOTE EXPLANATION")}
end

#to_sObject



12
13
14
# File 'lib/hulse/record.rb', line 12

def to_s
  section
end