class Arduino::Library::Presenters::Properties

Attributes

presented[RW]

Public Class Methods

from(file_or_url) click to toggle source

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

# 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
new(*args) click to toggle source
Calls superclass method
# File lib/arduino/library/presenters/properties.rb, line 31
def initialize(*args)
  super(*args)
  self.presented = ''
end

Public Instance Methods

present() click to toggle source

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.

# File lib/arduino/library/presenters/properties.rb, line 40
def present
  Types::LIBRARY_PROPERTIES.keys.each do |attr|
    attribute_presenter(attr)
  end
  presented
end

Private Instance Methods

attribute_presenter(attr) click to toggle source
# File lib/arduino/library/presenters/properties.rb, line 49
def attribute_presenter(attr)
  value = model.send(attr) if model && model.respond_to?(attr)
  return unless value
  if value.is_a?(Array)
    self.presented << "#{attr}=#{model.send(attr).join(',')}\n"
  else
    self.presented << "#{attr}=#{model.send(attr)}\n"
  end
end