Class: Hdo::StortingImporter::ParliamentIssue

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Inspectable

#short_inspect_string

Methods included from IvarEquality

#==, #__ivars__, #hash

Methods included from HasJsonSchema

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

Constructor Details

#initialize(external_id, summary, description, type, status, last_update, reference, document_group, committee, categories) ⇒ ParliamentIssue

Returns a new instance of ParliamentIssue.



82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 82

def initialize(external_id, summary, description, type, status, last_update,
               reference, document_group, committee, categories)
  @external_id    = external_id
  @summary        = summary
  @description    = description
  @type           = type
  @status         = status
  @last_update    = last_update
  @reference      = reference
  @document_group = document_group
  @committee      = committee
  @categories     = categories || []
end

Instance Attribute Details

#categoriesObject (readonly)

Returns the value of attribute categories.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def categories
  @categories
end

#committeeObject (readonly)

Returns the value of attribute committee.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def committee
  @committee
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def description
  @description
end

#document_groupObject (readonly)

Returns the value of attribute document_group.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def document_group
  @document_group
end

#external_idObject (readonly)

Returns the value of attribute external_id.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def external_id
  @external_id
end

#last_updateObject (readonly)

Returns the value of attribute last_update.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def last_update
  @last_update
end

#referenceObject (readonly)

Returns the value of attribute reference.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def reference
  @reference
end

#statusObject (readonly)

Returns the value of attribute status.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def status
  @status
end

#summaryObject (readonly)

Returns the value of attribute summary.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def summary
  @summary
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 10

def type
  @type
end

Class Method Details

.example(overrides = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 15

def self.example(overrides = nil)
  obj = new(
    "53520",
    "Inngåelse av avtale om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
    "Samtykke til inngåelse av avtale av 25. november 2011 om opprettelse av sekretariatet for Den nordlige dimensjons partnerskap for helse og livskvalitet (NDPHS)",
    "alminneligsak",
    "mottatt",
    "2012-04-20T00:00:00",
    "Prop. 90 S (2011-2012)",
    "proposisjon",
    "Transport- og kommunikasjonskomiteen",
    ['UTENRIKSSAKER', 'TRAKTATER', 'NORDISK SAMARBEID']
  )

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

  obj
end

.from_hash(hash) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 69

def self.from_hash(hash)
  new hash['external_id'],
      hash['summary'],
      hash['description'],
      hash['type'],
      hash['status'],
      hash['last_update'],
      hash['reference'],
      hash['document_group'],
      hash['committee'],
      hash['categories']
end

.from_storting_doc(doc) ⇒ Object



40
41
42
43
44
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 40

def self.from_storting_doc(doc)
  doc.css("saker_liste sak").map do |node|
    from_storting_node(node)
  end
end

.from_storting_node(node) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 46

def self.from_storting_node(node)
  external_id    = node.xpath("./id").first.text
  summary        = node.css("korttittel").first.text
  description    = Util.remove_newlines(node.css("tittel").first.text)
  type           = node.css("type").first.text
  status         = node.css("status").first.text
  last_update    = node.css("sist_oppdatert_dato").first.text
  reference      = node.css("henvisning").first.text
  document_group = node.css("dokumentgruppe").first.text

  committee_node = node.css("komite").first
  if committee_node && committee_node['nil'] != "true"
    committee = committee_node.css("navn").first.text
  end

  xcategories = node.css("emne")
  if xcategories.any?
    categories = xcategories.map { |xt| xt.css("navn").first.text }
  end

  new(external_id, summary, description, type, status, last_update, reference, document_group, committee, categories)
end

.json_exampleObject



36
37
38
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 36

def self.json_example
  Util.json_pretty example
end

Instance Method Details

#short_inspectObject



96
97
98
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 96

def short_inspect
  short_inspect_string :include => [:external_id, :summary]
end

#to_hashObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/hdo/storting_importer/parliament_issue.rb', line 100

def to_hash
  {
    'kind'           => self.class.kind,
    'external_id'    => @external_id,
    'summary'        => @summary,
    'description'    => @description,
    'type'           => @type,
    'status'         => @status,
    'last_update'    => @last_update,
    'reference'      => @reference,
    'document_group' => @document_group,
    'committee'      => @committee,
    'categories'     => @categories
  }
end