Class: Gedcomx::Date
- Inherits:
-
Object
- Object
- Gedcomx::Date
- Defined in:
- lib/gedcomx/date.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
Class Method Summary collapse
Instance Method Summary collapse
- #add_field(field) ⇒ Object
- #day ⇒ Object
-
#initialize(input = nil) ⇒ Date
constructor
A new instance of Date.
- #month ⇒ Object
- #original ⇒ Object
- #original=(input_string) ⇒ Object
- #to_java ⇒ Object
- #year ⇒ Object
Constructor Details
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
4 5 6 |
# File 'lib/gedcomx/date.rb', line 4 def fields @fields end |
Class Method Details
.create(attributes = {}) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/gedcomx/date.rb', line 10 def self.create(attributes = {}) new_date = self.new new_date.original = attributes[:original] if attributes[:original] attributes[:fields].each { |field| new_date.add_field(field) } if attributes[:fields].is_a? Array new_date end |
.create_simple(attributes = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gedcomx/date.rb', line 17 def self.create_simple(attributes = {}) day = attributes[:day] month = attributes[:month] year = attributes[:year] return nil unless ( day || month || year ) new_fields = [] full_string = '' if day full_string += day new_fields << Gedcomx::Field.create(values: [ { text: day, type: Gedcomx::TYPES[:day] } ]) end if month full_string += ' ' unless full_string.empty? full_string += month new_fields << Gedcomx::Field.create(values: [ { text: month, type: Gedcomx::TYPES[:month] } ]) end if year full_string += ' ' unless full_string.empty? full_string += year new_fields << Gedcomx::Field.create(values: [ { text: year, type: Gedcomx::TYPES[:year] } ]) end new_fields << Gedcomx::Field.create(values: [ { text: full_string, type: Gedcomx::TYPES[:original] } ]) self.create(fields: new_fields) end |
.java_class ⇒ Object
6 7 8 |
# File 'lib/gedcomx/date.rb', line 6 def self.java_class Java::OrgGedcomxConclusion::Date end |
Instance Method Details
#add_field(field) ⇒ Object
68 69 70 71 72 |
# File 'lib/gedcomx/date.rb', line 68 def add_field(field) return false unless field.is_a? Gedcomx::Field @date.add_field field.to_java @fields << field end |
#day ⇒ Object
53 54 55 56 |
# File 'lib/gedcomx/date.rb', line 53 def day day_field = @fields.select { |field| field.type == Gedcomx::TYPES[:day] }.first day_field.values.first.text if day_field end |
#month ⇒ Object
58 59 60 61 |
# File 'lib/gedcomx/date.rb', line 58 def month month_field = @fields.select { |field| field.type == Gedcomx::TYPES[:month] }.first month_field.values.first.text if month_field end |
#original ⇒ Object
74 75 76 |
# File 'lib/gedcomx/date.rb', line 74 def original @date.original end |
#original=(input_string) ⇒ Object
78 79 80 81 |
# File 'lib/gedcomx/date.rb', line 78 def original=(input_string) return false unless input_string.is_a? String @date.original = input_string end |
#to_java ⇒ Object
83 84 85 |
# File 'lib/gedcomx/date.rb', line 83 def to_java @date end |