Class: Arduino::Library::Presenters::Properties

Inherits:
Struct
  • Object
show all
Extended by:
Utilities
Defined in:
lib/arduino/library/presenters/properties.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utilities

backup_previous_library, debug, download, open_plain_or_gzipped, read_file_or_url, short_time

Constructor Details

#initialize(*args) ⇒ Properties

Returns a new instance of Properties.



31
32
33
34
# File 'lib/arduino/library/presenters/properties.rb', line 31

def initialize(*args)
  super(*args)
  self.presented = ''
end

Instance Attribute Details

#modelObject

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



7
8
9
# File 'lib/arduino/library/presenters/properties.rb', line 7

def model
  @model
end

#presentedObject

Returns the value of attribute presented.



29
30
31
# File 'lib/arduino/library/presenters/properties.rb', line 29

def presented
  @presented
end

Class Method Details

.from(file_or_url) ⇒ Object

Class method, that reads a properties file and returns a properly validated Arduino::Library::Model instance.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/arduino/library/presenters/properties.rb', line 12

def from(file_or_url)
  file  = read_file_or_url(file_or_url)
  props = file.read.split(/\n/)
  hash  = {}
  props.each do |line|
    attr, value = line.split('=')
    attr        = attr.to_sym
    if Types::ARRAY_ATTRIBUTES.include?(attr)
      hash[attr] = value.split(',')
    else
      hash[attr] = value
    end
  end
  ::Arduino::Library::Model.from_hash(hash)
end

Instance Method Details

#presentObject

Primary instance method, returns a string representing a library.properties format file, using the model. The presented value is cached in the #presented public instance variable.



40
41
42
43
44
45
# File 'lib/arduino/library/presenters/properties.rb', line 40

def present
  Types::LIBRARY_PROPERTIES.keys.each do |attr|
    attribute_presenter(attr)
  end
  presented
end