Class: Hdo::StortingImporter::Party

Inherits:
Object
  • Object
show all
Includes:
HasJsonSchema, IvarEquality
Defined in:
lib/hdo/storting_importer/party.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, name) ⇒ Party

Returns a new instance of Party.



34
35
36
37
# File 'lib/hdo/storting_importer/party.rb', line 34

def initialize(external_id, name)
  @external_id       = external_id
  @name              = name
end

Instance Attribute Details

#external_idObject (readonly)

Returns the value of attribute external_id.



7
8
9
# File 'lib/hdo/storting_importer/party.rb', line 7

def external_id
  @external_id
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/hdo/storting_importer/party.rb', line 7

def name
  @name
end

Class Method Details

.example(overrides = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/hdo/storting_importer/party.rb', line 12

def self.example(overrides = nil)
  obj = new("A", "Arbeiderpartiet")

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

  obj
end

.from_hash(hash) ⇒ Object



29
30
31
32
# File 'lib/hdo/storting_importer/party.rb', line 29

def self.from_hash(hash)
  new hash['external_id'],
      hash['name']
end

.from_storting_doc(doc) ⇒ Object



22
23
24
25
26
27
# File 'lib/hdo/storting_importer/party.rb', line 22

def self.from_storting_doc(doc)
  doc.css("partier_liste parti").map do |node|
    new node.css("id").first.text,
        node.css("navn").first.text
  end
end

Instance Method Details

#to_hashObject



43
44
45
46
47
48
49
# File 'lib/hdo/storting_importer/party.rb', line 43

def to_hash
  {
    'kind'        => self.class.kind,
    'external_id' => @external_id,
    'name'        => @name,
  }
end