Class: ArduinoCI::LibraryProperties

Inherits:
Object
  • Object
show all
Defined in:
lib/arduino_ci/library_properties.rb

Overview

Information about an Arduino library package, as specified by the library.properties file

See arduino.github.io/arduino-cli/library-specification/#libraryproperties-file-format

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ LibraryProperties

Returns a new instance of LibraryProperties.

Parameters:

  • path (Pathname)

    The path to the library.properties file

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/arduino_ci/library_properties.rb', line 12

def initialize(path)
  @fields = {}
  raise ArgumentError, "Library properties at '#{path}' doesn't exist" unless path.exist?

  File.foreach(path) do |line_with_delim|
    line = line_with_delim.chomp
    parts = line.split("=", 2)
    next if parts[0].nil?
    next if parts[0].empty?
    next if parts[1].nil?

    @fields[parts[0]] = parts[1] unless parts[1].empty?
  end
end

Instance Attribute Details

#architecturesObject (readonly)

Returns property _csv of the library.properties file, formatted with the function {}.

Returns:

  • property _csv of the library.properties file, formatted with the function {}



86
# File 'lib/arduino_ci/library_properties.rb', line 86

field_reader :architectures, :_csv

#authorObject (readonly)

Returns property _csv of the library.properties file, formatted with the function {}.

Returns:

  • property _csv of the library.properties file, formatted with the function {}



80
# File 'lib/arduino_ci/library_properties.rb', line 80

field_reader :author, :_csv

#categoryObject (readonly)

Returns property of the library.properties file, formatted with the function {}.

Returns:

  • property of the library.properties file, formatted with the function {}



84
# File 'lib/arduino_ci/library_properties.rb', line 84

field_reader :category

#dependsObject (readonly)

Returns property _csv of the library.properties file, formatted with the function {}.

Returns:

  • property _csv of the library.properties file, formatted with the function {}



87
# File 'lib/arduino_ci/library_properties.rb', line 87

field_reader :depends, :_csv

#dot_a_linkageObject (readonly)

Returns property _bool of the library.properties file, formatted with the function {}.

Returns:

  • property _bool of the library.properties file, formatted with the function {}



88
# File 'lib/arduino_ci/library_properties.rb', line 88

field_reader :dot_a_linkage, :_bool

#fieldsHash (readonly)

Returns The properties file parsed as a hash.

Returns:

  • (Hash)

    The properties file parsed as a hash



9
10
11
# File 'lib/arduino_ci/library_properties.rb', line 9

def fields
  @fields
end

#includesObject (readonly)

Returns property _csv of the library.properties file, formatted with the function {}.

Returns:

  • property _csv of the library.properties file, formatted with the function {}



89
# File 'lib/arduino_ci/library_properties.rb', line 89

field_reader :includes, :_csv

#ldflagsObject (readonly)

Returns property _csv of the library.properties file, formatted with the function {}.

Returns:

  • property _csv of the library.properties file, formatted with the function {}



91
# File 'lib/arduino_ci/library_properties.rb', line 91

field_reader :ldflags, :_csv

#maintainerObject (readonly)

Returns property of the library.properties file, formatted with the function {}.

Returns:

  • property of the library.properties file, formatted with the function {}



81
# File 'lib/arduino_ci/library_properties.rb', line 81

field_reader :maintainer

#nameObject (readonly)

Returns property of the library.properties file, formatted with the function {}.

Returns:

  • property of the library.properties file, formatted with the function {}



78
# File 'lib/arduino_ci/library_properties.rb', line 78

field_reader :name

#paragraphObject (readonly)

Returns property of the library.properties file, formatted with the function {}.

Returns:

  • property of the library.properties file, formatted with the function {}



83
# File 'lib/arduino_ci/library_properties.rb', line 83

field_reader :paragraph

#precompiledObject (readonly)

Returns property _bool of the library.properties file, formatted with the function {}.

Returns:

  • property _bool of the library.properties file, formatted with the function {}



90
# File 'lib/arduino_ci/library_properties.rb', line 90

field_reader :precompiled, :_bool

#sentenceObject (readonly)

Returns property of the library.properties file, formatted with the function {}.

Returns:

  • property of the library.properties file, formatted with the function {}



82
# File 'lib/arduino_ci/library_properties.rb', line 82

field_reader :sentence

#urlObject (readonly)

Returns property of the library.properties file, formatted with the function {}.

Returns:

  • property of the library.properties file, formatted with the function {}



85
# File 'lib/arduino_ci/library_properties.rb', line 85

field_reader :url

#versionObject (readonly)

Returns property of the library.properties file, formatted with the function {}.

Returns:

  • property of the library.properties file, formatted with the function {}



79
# File 'lib/arduino_ci/library_properties.rb', line 79

field_reader :version

Class Method Details

._bool(input) ⇒ Array<String>

Parse a value as a boolean

Parameters:

  • input (String)

Returns:

  • (Array<String>)

    The individual values



74
75
76
# File 'lib/arduino_ci/library_properties.rb', line 74

def self._bool(input)
  input == "true"  # no indication given in the docs that anything but lowercase "true" indicates boolean true.
end

._csv(input) ⇒ Array<String>

Parse a value as a comma-separated array

Parameters:

  • input (String)

Returns:

  • (Array<String>)

    The individual values



67
68
69
# File 'lib/arduino_ci/library_properties.rb', line 67

def self._csv(input)
  input.split(",").map(&:strip)
end

.field_reader(name, formatter = nil) ⇒ void

This method returns an undefined value.

Enable a shortcut syntax for library property accessors, in the style of ‘attr_accessor` metaprogramming. This is used to create a named field pointing to a specific property in the file, optionally applying a specific formatting function.

The formatting function MUST be a static method on this class.  This is a limitation caused by the desire
to both (1) expose the formatters outside this class, and (2) use them for metaprogramming without the
having to name the entire function.  field_reader is a static method, so if not for the fact that
`self.class.methods.include? formatter` fails to work for class methods in this context (unlike
`self.methods.include?`, which properly finds instance methods), I would allow either one and just
conditionally `define_method` the proper definition

Parameters:

  • name (String)

    What the accessor will be called

  • field_num (Integer)

    The name of the key of the property

  • formatter (Symbol) (defaults to: nil)

    The symbol for the formatting function to apply to the field (optional)



55
56
57
58
59
60
61
62
# File 'lib/arduino_ci/library_properties.rb', line 55

def self.field_reader(name, formatter = nil)
  key = name.to_s
  if formatter.nil?
    define_method(name) { @fields[key] }
  else
    define_method(name) { @fields.key?(key) ? self.class.send(formatter.to_sym, @fields[key]) : nil }
  end
end

Instance Method Details

#full_paragraphString

The value of sentence always will be prepended, so you should start by writing the second sentence here

(according to the docs)

Returns:

  • (String)

    the sentence and paragraph together



97
98
99
# File 'lib/arduino_ci/library_properties.rb', line 97

def full_paragraph
  [sentence, paragraph].join(" ")
end

#to_hHash

Returns the properties as a hash, all strings.

Returns:

  • (Hash)

    the properties as a hash, all strings



28
29
30
# File 'lib/arduino_ci/library_properties.rb', line 28

def to_h
  Hash[@fields.map { |k, _| [k.to_sym, send(k)] }]
end

#to_sString

Returns the string representation.

Returns:

  • (String)

    the string representation



33
34
35
# File 'lib/arduino_ci/library_properties.rb', line 33

def to_s
  to_h.to_s
end