Class: Hdo::StortingImporter::ParliamentSession

Inherits:
Object
  • Object
show all
Includes:
HasJsonSchema, IvarEquality
Defined in:
lib/hdo/storting_importer/parliament_session.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from IvarEquality

#==, #__ivars__, #hash

Methods included from HasJsonSchema

#as_json, included, schemas, #to_json, #valid?, #validate!

Constructor Details

#initialize(external_id, start_date, end_date) ⇒ ParliamentSession

Returns a new instance of ParliamentSession.



41
42
43
44
45
# File 'lib/hdo/storting_importer/parliament_session.rb', line 41

def initialize(external_id, start_date, end_date)
  @external_id = external_id
  @start_date  = start_date
  @end_date    = end_date
end

Instance Attribute Details

#end_dateObject (readonly)

Returns the value of attribute end_date.



9
10
11
# File 'lib/hdo/storting_importer/parliament_session.rb', line 9

def end_date
  @end_date
end

#external_idObject (readonly)

Returns the value of attribute external_id.



9
10
11
# File 'lib/hdo/storting_importer/parliament_session.rb', line 9

def external_id
  @external_id
end

#start_dateObject (readonly)

Returns the value of attribute start_date.



9
10
11
# File 'lib/hdo/storting_importer/parliament_session.rb', line 9

def start_date
  @start_date
end

Class Method Details

.example(overrides = nil) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/hdo/storting_importer/parliament_session.rb', line 31

def self.example(overrides = nil)
  obj = new('2012-2013', Date.parse('2012-10-01'), Date.parse('2013-09-30'))

  if overrides
    obj = from_hash(obj.to_hash.merge(overrides))
  end

  obj
end

.from_hash(hash) ⇒ Object



25
26
27
28
29
# File 'lib/hdo/storting_importer/parliament_session.rb', line 25

def self.from_hash(hash)
  new hash['external_id'],
      hash['start_date'] && Date.parse(hash['start_date']),
      hash['end_date'] && Date.parse(hash['end_date'])
end

.from_storting_doc(doc) ⇒ Object



13
14
15
16
17
# File 'lib/hdo/storting_importer/parliament_session.rb', line 13

def self.from_storting_doc(doc)
  doc.css("sesjoner_liste sesjon").map do |node|
    from_storting_node node
  end
end

.from_storting_node(node) ⇒ Object



19
20
21
22
23
# File 'lib/hdo/storting_importer/parliament_session.rb', line 19

def self.from_storting_node(node)
  new node.css("id").text,
      Date.parse(node.css("fra").text),
      Date.parse(node.css("til").text)
end

Instance Method Details

#to_hashObject



47
48
49
50
51
52
53
54
# File 'lib/hdo/storting_importer/parliament_session.rb', line 47

def to_hash
  {
    'kind'        => self.class.kind,
    'external_id' => @external_id,
    'start_date'  => @start_date && @start_date.iso8601,
    'end_date'    => @end_date && @end_date.iso8601
  }
end