Class: Noft::Model::IconSet

Inherits:
Object
  • Object
show all
Defined in:
lib/noft/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



36
37
38
# File 'lib/noft/model.rb', line 36

def description
  @description
end

#display_stringObject

A human readable name for icon set



35
36
37
# File 'lib/noft/model.rb', line 35

def display_string
  @display_string
end

#font_fileObject

The local filename of the font file



46
47
48
# File 'lib/noft/model.rb', line 46

def font_file
  @font_file
end

#licenseObject

The license of the library



42
43
44
# File 'lib/noft/model.rb', line 42

def license
  @license
end

#license_urlObject

The url of the license



44
45
46
# File 'lib/noft/model.rb', line 44

def license_url
  @license_url
end

#urlObject

The url to the source library



40
41
42
# File 'lib/noft/model.rb', line 40

def url
  @url
end

#versionObject

The version of the source library from which this was extracted



38
39
40
# File 'lib/noft/model.rb', line 38

def version
  @version
end

Instance Method Details

#font_file?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/noft/model.rb', line 48

def font_file?
  !(@font_file ||= nil).nil?
end

#read_from(data, filter = nil) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/noft/model.rb', line 56

def read_from(data, filter = nil)
  self.display_string = data['displayString'] if data['displayString']
  self.description = data['description'] if data['description']
  self.version = data['version'] if data['version']
  self.url = data['url'] if data['url']
  self.license = data['license'] if data['license']
  self.license_url = data['licenseUrl'] if data['licenseUrl']

  data['icons'].each_pair do |icon_name, icon_data|
    if filter.nil? || (filter.is_a?(Proc) && filter.call(icon_name)) || (filter.is_a?(Array) && filter.include?(icon_name))
      self.icon(icon_name.to_sym).read_from(icon_data)
    end
  end if data['icons']
end

#to_hObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/noft/model.rb', line 71

def to_h
  data = {}
  data[:name] = self.name
  data[:displayString] = self.display_string if self.display_string
  data[:description] = self.description if self.description
  data[:version] = self.version if self.version
  data[:url] = self.url if self.url
  data[:license] = self.license if self.license
  data[:licenseUrl] = self.license_url if self.license_url

  data[:icons] = {}
  self.icons.each do |icon|
    data[:icons][icon.name] = icon.to_h
  end

  data
end

#write_to(filename) ⇒ Object



52
53
54
# File 'lib/noft/model.rb', line 52

def write_to(filename)
  File.write(filename, JSON.pretty_generate(to_h) + "\n")
end