Class: Libis::Tools::Metadata::FieldFormat
- Defined in:
- lib/libis/tools/metadata/field_format.rb
Instance Attribute Summary collapse
-
#join ⇒ Object
Returns the value of attribute join.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#postfix ⇒ Object
Returns the value of attribute postfix.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
- #[](*parts) ⇒ Object
- #add(part) ⇒ Object
- #add_default_options(options = {}) ⇒ Object
- #add_options(options = {}) ⇒ Object
-
#initialize(*parts) ⇒ FieldFormat
constructor
A new instance of FieldFormat.
- #to_s ⇒ Object
Constructor Details
#initialize(*parts) ⇒ FieldFormat
14 15 16 17 |
# File 'lib/libis/tools/metadata/field_format.rb', line 14 def initialize(*parts) @parts = [] self[*parts] end |
Instance Attribute Details
#join ⇒ Object
Returns the value of attribute join.
11 12 13 |
# File 'lib/libis/tools/metadata/field_format.rb', line 11 def join @join end |
#parts ⇒ Object
Returns the value of attribute parts.
9 10 11 |
# File 'lib/libis/tools/metadata/field_format.rb', line 9 def parts @parts end |
#postfix ⇒ Object
Returns the value of attribute postfix.
12 13 14 |
# File 'lib/libis/tools/metadata/field_format.rb', line 12 def postfix @postfix end |
#prefix ⇒ Object
Returns the value of attribute prefix.
10 11 12 |
# File 'lib/libis/tools/metadata/field_format.rb', line 10 def prefix @prefix end |
Class Method Details
.from(*h) ⇒ Object
49 50 51 |
# File 'lib/libis/tools/metadata/field_format.rb', line 49 def self.from(*h) self.new(*h) end |
Instance Method Details
#[](*parts) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/libis/tools/metadata/field_format.rb', line 41 def [](*parts) = parts.last.is_a?(Hash) ? parts.pop : {} add parts x = .delete(:parts) add x if x end |
#add(part) ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/libis/tools/metadata/field_format.rb', line 66 def add(part) case part when Hash @parts << Libis::Tools::Metadata::FieldFormat::from(part) when Array part.each { |x| add x } else @parts << part end end |
#add_default_options(options = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/libis/tools/metadata/field_format.rb', line 33 def ( = {}) .delete(:prefix) if @prefix .delete(:postfix) if @postfix .delete(:fix) if @prefix or @postfix .delete(:join) if @join end |
#add_options(options = {}) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/libis/tools/metadata/field_format.rb', line 19 def ( = {}) if [:fix] if [:fix].size == 2 @prefix, @postfix = [:fix].split('') else @prefix, @postfix = [:fix].split('|') end end @join = [:join] if [:join] @prefix = FieldFormat::from([:prefix]) if [:prefix] @postfix = FieldFormat::from([:postfix]) if [:postfix] self end |
#to_s ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/libis/tools/metadata/field_format.rb', line 53 def to_s @parts.delete_if { |x| x.nil? or (x.is_a? String and x.empty?) or (x.is_a? Libis::Tools::Metadata::FieldFormat and x.to_s.empty?) } result = @parts.join(@join) unless result.empty? result = (@prefix || '').to_s + result + (@postfix || '').to_s end result end |