Module: Hdo::StortingImporter

Defined in:
lib/hdo/storting_importer.rb,
lib/hdo/storting_importer/cli.rb,
lib/hdo/storting_importer/util.rb,
lib/hdo/storting_importer/vote.rb,
lib/hdo/storting_importer/issue.rb,
lib/hdo/storting_importer/party.rb,
lib/hdo/storting_importer/promise.rb,
lib/hdo/storting_importer/version.rb,
lib/hdo/storting_importer/category.rb,
lib/hdo/storting_importer/district.rb,
lib/hdo/storting_importer/committee.rb,
lib/hdo/storting_importer/converter.rb,
lib/hdo/storting_importer/data_source.rb,
lib/hdo/storting_importer/inspectable.rb,
lib/hdo/storting_importer/proposition.rb,
lib/hdo/storting_importer/fusion_table.rb,
lib/hdo/storting_importer/ivar_equality.rb,
lib/hdo/storting_importer/representative.rb,
lib/hdo/storting_importer/api_data_source.rb,
lib/hdo/storting_importer/has_json_schema.rb,
lib/hdo/storting_importer/disk_data_source.rb,
lib/hdo/storting_importer/parsing_data_source.rb

Defined Under Namespace

Modules: HasJsonSchema, Inspectable, IvarEquality, Util Classes: ApiDataSource, CLI, Category, Committee, Converter, DataSource, DiskDataSource, District, Field, FusionTable, Issue, ParsingDataSource, Party, Promise, Proposition, Representative, ValidationError, Vote

Constant Summary collapse

EXTERNAL_ID_FIELD =
Field.new(:externalId, false, :string, 'An optional external id, matching potential id fields in the input data. This is useful if you want to reimport previous data without creating duplicates.')
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.libObject



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

def self.lib
  @lib ||= Pathname.new(File.expand_path("../..", __FILE__))
end

.loggerObject



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

def self.logger
  @logger ||= (
    out = $stderr # should be able to pipe output to a file

    if defined?(Rails)
      klass = Class.new(Logger) do
        def format_message(severity, timestamp, progname, msg)
          "#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
        end
      end

      klass.new(out)
    else
      Logger.new(out)
    end
  )

end


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/hdo/storting_importer.rb', line 39

def self.print_types(opts = {})
  out = opts[:io] || $stdout
  xml = !!opts[:xml]

  max_name_size = 0
  max_type_size  = 0

  type_strings = []


  types.each do |type|
    type.fields.each do |e|
      required = 'required' if e.required
      type_strings << (type_string = "#{required}:#{e.type}")

      max_name_size = [e.name.size, max_name_size].max
      max_type_size = [type_string.size, max_type_size].max
    end
  end

  types.each_with_index do |type, type_idx|
    out.puts "\x1b[1m#{type.kind}\x1b[0m\n"

    type.fields.each_with_index do |field, field_idx|

      parts = [
        field.name.to_s.rjust(max_name_size + 5),
        type_strings[type_idx + field_idx].rjust(max_type_size),
        "\t#{field.description}"
      ]

      out.puts parts.join ' '
    end

    out.puts "\n\n"

    if xml
      puts type.xml_example.split("\n")
      puts "\n\n"
    end
  end
end

.rootObject



17
18
19
# File 'lib/hdo/storting_importer.rb', line 17

def self.root
  @root ||= Pathname.new(File.expand_path("../../..", __FILE__))
end

.typesObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/hdo/storting_importer.rb', line 25

def self.types
  [
    Party,
    Committee,
    District,
    Representative,
    Category,
    Issue,
    Vote,
    Proposition,
    Promise
  ]
end