Class: EacRubyUtils::CustomFormat::String
- Defined in:
- lib/eac_ruby_utils/custom_format.rb
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
-
#initialize(format, string) ⇒ String
constructor
A new instance of String.
- #mapping ⇒ Object
- #sequences ⇒ Object
- #source_object_value(object, method) ⇒ Object
- #with(source_object) ⇒ Object
Constructor Details
#initialize(format, string) ⇒ String
Returns a new instance of String.
22 23 24 25 |
# File 'lib/eac_ruby_utils/custom_format.rb', line 22 def initialize(format, string) @format = format @string = string end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
20 21 22 |
# File 'lib/eac_ruby_utils/custom_format.rb', line 20 def format @format end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
20 21 22 |
# File 'lib/eac_ruby_utils/custom_format.rb', line 20 def string @string end |
Instance Method Details
#mapping ⇒ Object
27 28 29 |
# File 'lib/eac_ruby_utils/custom_format.rb', line 27 def mapping @mapping ||= format.mapping.slice(*sequences) end |
#sequences ⇒ Object
31 32 33 |
# File 'lib/eac_ruby_utils/custom_format.rb', line 31 def sequences @sequences ||= string.scan(SEQUENCE_PATTERN).map(&:first).uniq.map(&:to_sym) end |
#source_object_value(object, method) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/eac_ruby_utils/custom_format.rb', line 35 def source_object_value(object, method) return object.send(method) if object.respond_to?(method) return object[method] if object.respond_to?('[]') raise ::ArgumentError, "Methods \"#{method}\" or \"[]\" not found for #{object}" end |