Class: ArduinoCI::LibraryProperties
- Inherits:
-
Object
- Object
- ArduinoCI::LibraryProperties
- 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
-
#architectures ⇒ Object
readonly
Property _csv of the library.properties file, formatted with the function {}.
-
#author ⇒ Object
readonly
Property _csv of the library.properties file, formatted with the function {}.
-
#category ⇒ Object
readonly
Property of the library.properties file, formatted with the function {}.
-
#depends ⇒ Object
readonly
Property _csv of the library.properties file, formatted with the function {}.
-
#dot_a_linkage ⇒ Object
readonly
Property _bool of the library.properties file, formatted with the function {}.
-
#fields ⇒ Hash
readonly
The properties file parsed as a hash.
-
#includes ⇒ Object
readonly
Property _csv of the library.properties file, formatted with the function {}.
-
#ldflags ⇒ Object
readonly
Property _csv of the library.properties file, formatted with the function {}.
-
#maintainer ⇒ Object
readonly
Property of the library.properties file, formatted with the function {}.
-
#name ⇒ Object
readonly
Property of the library.properties file, formatted with the function {}.
-
#paragraph ⇒ Object
readonly
Property of the library.properties file, formatted with the function {}.
-
#precompiled ⇒ Object
readonly
Property _bool of the library.properties file, formatted with the function {}.
-
#sentence ⇒ Object
readonly
Property of the library.properties file, formatted with the function {}.
-
#url ⇒ Object
readonly
Property of the library.properties file, formatted with the function {}.
-
#version ⇒ Object
readonly
Property of the library.properties file, formatted with the function {}.
Class Method Summary collapse
-
._bool(input) ⇒ Array<String>
Parse a value as a boolean.
-
._csv(input) ⇒ Array<String>
Parse a value as a comma-separated array.
-
.field_reader(name, formatter = nil) ⇒ void
Enable a shortcut syntax for library property accessors, in the style of ‘attr_accessor` metaprogramming.
Instance Method Summary collapse
-
#full_paragraph ⇒ String
The value of sentence always will be prepended, so you should start by writing the second sentence here.
-
#initialize(path) ⇒ LibraryProperties
constructor
A new instance of LibraryProperties.
-
#to_h ⇒ Hash
The properties as a hash, all strings.
-
#to_s ⇒ String
The string representation.
Constructor Details
#initialize(path) ⇒ LibraryProperties
Returns a new instance of LibraryProperties.
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
#architectures ⇒ Object (readonly)
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 |
#author ⇒ Object (readonly)
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 |
#category ⇒ Object (readonly)
Returns property of the library.properties file, formatted with the function {}.
84 |
# File 'lib/arduino_ci/library_properties.rb', line 84 field_reader :category |
#depends ⇒ Object (readonly)
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_linkage ⇒ Object (readonly)
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 |
#fields ⇒ Hash (readonly)
Returns The properties file parsed as a hash.
9 10 11 |
# File 'lib/arduino_ci/library_properties.rb', line 9 def fields @fields end |
#includes ⇒ Object (readonly)
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 |
#ldflags ⇒ Object (readonly)
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 |
#maintainer ⇒ Object (readonly)
Returns property of the library.properties file, formatted with the function {}.
81 |
# File 'lib/arduino_ci/library_properties.rb', line 81 field_reader :maintainer |
#name ⇒ Object (readonly)
Returns property of the library.properties file, formatted with the function {}.
78 |
# File 'lib/arduino_ci/library_properties.rb', line 78 field_reader :name |
#paragraph ⇒ Object (readonly)
Returns property of the library.properties file, formatted with the function {}.
83 |
# File 'lib/arduino_ci/library_properties.rb', line 83 field_reader :paragraph |
#precompiled ⇒ Object (readonly)
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 |
#sentence ⇒ Object (readonly)
Returns property of the library.properties file, formatted with the function {}.
82 |
# File 'lib/arduino_ci/library_properties.rb', line 82 field_reader :sentence |
#url ⇒ Object (readonly)
Returns property of the library.properties file, formatted with the function {}.
85 |
# File 'lib/arduino_ci/library_properties.rb', line 85 field_reader :url |
#version ⇒ Object (readonly)
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
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
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
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_paragraph ⇒ String
The value of sentence always will be prepended, so you should start by writing the second sentence here
(according to the docs)
97 98 99 |
# File 'lib/arduino_ci/library_properties.rb', line 97 def full_paragraph [sentence, paragraph].join(" ") end |
#to_h ⇒ Hash
Returns 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_s ⇒ String
Returns the string representation.
33 34 35 |
# File 'lib/arduino_ci/library_properties.rb', line 33 def to_s to_h.to_s end |