Class: Gedcomx::Field
- Inherits:
-
Object
- Object
- Gedcomx::Field
- Defined in:
- lib/gedcomx/field.rb
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #add_value(value_string, input_type = nil) ⇒ Object
-
#initialize(input = nil) ⇒ Field
constructor
A new instance of Field.
- #to_java ⇒ Object
- #type ⇒ Object
- #type=(input_type) ⇒ Object
Constructor Details
#initialize(input = nil) ⇒ Field
Returns a new instance of Field.
28 29 30 31 32 |
# File 'lib/gedcomx/field.rb', line 28 def initialize(input = nil) @field = input || self.class.java_class.new @values = [] @values = @field.values.map { |value| Gedcomx::FieldValue.new(value) } if @field.values end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
4 5 6 |
# File 'lib/gedcomx/field.rb', line 4 def values @values end |
Class Method Details
.create(attributes = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/gedcomx/field.rb', line 14 def self.create(attributes = {}) new_field = self.new values = attributes[:values] new_field.type = attributes[:type] if attributes[:type] if values.is_a? Array values.each do |value| next unless value.is_a? Hash new_field.add_value(value[:text], value[:type]) end end new_field end |
.java_class ⇒ Object
6 7 8 |
# File 'lib/gedcomx/field.rb', line 6 def self.java_class Java::OrgGedcomxRecords::Field end |
.java_value_class ⇒ Object
10 11 12 |
# File 'lib/gedcomx/field.rb', line 10 def self.java_value_class Java::OrgGedcomxRecords::FieldValue end |
Instance Method Details
#add_value(value_string, input_type = nil) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/gedcomx/field.rb', line 34 def add_value(value_string, input_type = nil) value = Gedcomx::FieldValue.new value.text = value_string value.type = input_type if input_type @field.add_value value.to_java @values << value end |
#to_java ⇒ Object
50 51 52 |
# File 'lib/gedcomx/field.rb', line 50 def to_java @field end |
#type ⇒ Object
42 43 44 |
# File 'lib/gedcomx/field.rb', line 42 def type @field.get_type.to_s end |
#type=(input_type) ⇒ Object
46 47 48 |
# File 'lib/gedcomx/field.rb', line 46 def type=(input_type) @field.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type) end |