Class: OsxContactsImporter

Inherits:
Object
  • Object
show all
Defined in:
lib/label_definitions/osx_contacts_importer.rb

Constant Summary collapse

CONTACTS_METRICS =
'/Applications/Contacts.app/Contents/Resources/uk.lproj/ABLabelMetrics.plist'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_string = nil) ⇒ OsxContactsImporter

Returns a new instance of OsxContactsImporter.



9
10
11
# File 'lib/label_definitions/osx_contacts_importer.rb', line 9

def initialize(data_string = nil)
  @metrics = data_string || File.read(CONTACTS_METRICS)
end

Instance Attribute Details

#metricsObject (readonly)

Returns the value of attribute metrics.



5
6
7
# File 'lib/label_definitions/osx_contacts_importer.rb', line 5

def metrics
  @metrics
end

Instance Method Details

#labelsObject



29
30
31
32
33
34
35
36
37
# File 'lib/label_definitions/osx_contacts_importer.rb', line 29

def labels
  Nokogiri::XML(metrics).
    xpath('//array/dict/array/dict').
    map do |label|
      new_label Hash[*label.children.reject { |x| x.children.length.zero? }.map(&:text)]
    end.
    compact.
    sort_by(&:name)
end

#to_yamlObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/label_definitions/osx_contacts_importer.rb', line 13

def to_yaml
  labels.map do |label|
    <<END
#{label.name}:
rows: #{label.rows}
columns: #{label.columns}
width: #{label.width}
height: #{label.height}
row_gutter: #{label.row_gutter}
column_gutter: #{label.column_gutter}
page_width: #{label.page.width}
page_height: #{label.page.height}
END
  end.join
end