Class: Hdo::StortingImporter::ParliamentSession
- Inherits:
-
Object
- Object
- Hdo::StortingImporter::ParliamentSession
- Includes:
- HasJsonSchema, IvarEquality
- Defined in:
- lib/hdo/storting_importer/parliament_session.rb
Instance Attribute Summary collapse
-
#end_date ⇒ Object
readonly
Returns the value of attribute end_date.
-
#external_id ⇒ Object
readonly
Returns the value of attribute external_id.
-
#start_date ⇒ Object
readonly
Returns the value of attribute start_date.
Class Method Summary collapse
- .example(overrides = nil) ⇒ Object
- .from_hash(hash) ⇒ Object
- .from_storting_doc(doc) ⇒ Object
- .from_storting_node(node) ⇒ Object
Instance Method Summary collapse
-
#initialize(external_id, start_date, end_date) ⇒ ParliamentSession
constructor
A new instance of ParliamentSession.
- #to_hash ⇒ Object
Methods included from IvarEquality
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_date ⇒ Object (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_id ⇒ Object (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_date ⇒ Object (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_hash ⇒ Object
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 |