Class: Gedcomx::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/gedcomx/name.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input = nil) ⇒ Name

Returns a new instance of Name.



65
66
67
68
69
70
# File 'lib/gedcomx/name.rb', line 65

def initialize(input = nil)
  @name = input || self.class.java_class.new
  @date = Gedcomx::Date.new(@name.get_date) if @name.get_date
  @forms = []
  @forms = @name.get_name_forms.map { |form| Gedcomx::NameForm.new(form) } if @name.get_name_forms
end

Instance Attribute Details

#dateObject

Returns the value of attribute date.



4
5
6
# File 'lib/gedcomx/name.rb', line 4

def date
  @date
end

#formsObject (readonly)

Returns the value of attribute forms.



4
5
6
# File 'lib/gedcomx/name.rb', line 4

def forms
  @forms
end

Class Method Details

.build_simple(attributes = {}) ⇒ Object



10
11
12
13
14
15
16
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
46
47
48
# File 'lib/gedcomx/name.rb', line 10

def self.build_simple(attributes = {})
  first = attributes[:first]
  last = attributes[:last]
  name_form = Gedcomx::NameForm.new
  name_form.full_text = attributes[:full] if attributes[:full]

  if first
    field = Gedcomx::Field.create( first_attributes = {
      values: [ { text: first, type: Gedcomx::TYPES[:original] } ],
      type: Gedcomx::TYPES[:given]
    } )

    name_part = Gedcomx::NamePart.create( first_attributes = {
      fields: [ field ],
      value: first,
      type: Gedcomx::TYPES[:given]
    })

    name_form.add_part(name_part)
  end

  if last
    field = Gedcomx::Field.create( last_attributes = {
      values: [ { text: last, type: Gedcomx::TYPES[:original] } ],
      type: Gedcomx::TYPES[:surname]
    } )

    name_part = Gedcomx::NamePart.create( last_attributes = {
      fields: [ field ],
      value: last,
      type: Gedcomx::TYPES[:surname]
    })

    name_form.add_part(name_part)
  end

  attributes[:forms] = [name_form]
  self.create(attributes)
end

.create(attributes = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gedcomx/name.rb', line 50

def self.create(attributes = {})
  new_name = self.new
  new_name.confidence = attributes[:confidence] if attributes[:confidence]
  new_name.preferred = attributes[:preferred] if attributes[:preferred]
  new_name.language = attributes[:language] if attributes[:language]
  new_name.type = attributes[:type] if attributes[:type]

  if attributes[:type]
    puts attributes[:type]
  end

  attributes[:forms].each { |form| new_name.add_form(form) } if attributes[:forms].is_a? Array
  new_name
end

.java_classObject



6
7
8
# File 'lib/gedcomx/name.rb', line 6

def self.java_class
  Java::OrgGedcomxConclusion::Name
end

Instance Method Details

#add_form(form) ⇒ Object



72
73
74
75
76
# File 'lib/gedcomx/name.rb', line 72

def add_form(form)
  return false unless form.is_a? Gedcomx::NameForm
  @name.add_name_form form.to_java
  @forms << form
end

#confidenceObject



84
85
86
# File 'lib/gedcomx/name.rb', line 84

def confidence
  @name.get_confidence
end

#confidence=(input_confidence) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/gedcomx/name.rb', line 88

def confidence=(input_confidence)
  if input_confidence.is_a? Gedcomx.java_uri_class
   @name.confidence = input_confidence
  else
    @name.confidence = Gedcomx.new_uri(input_confidence)
  end
end

#languageObject



105
106
107
# File 'lib/gedcomx/name.rb', line 105

def language
  @name.get_lang
end

#language=(input_language) ⇒ Object



109
110
111
112
# File 'lib/gedcomx/name.rb', line 109

def language=(input_language)
  return false unless input_language.is_a? String
  @name.lang = input_language
end

#preferred=(input_boolean) ⇒ Object



100
101
102
103
# File 'lib/gedcomx/name.rb', line 100

def preferred=(input_boolean)
  return false unless input_boolean.is_a? Boolean
  @name.preferred = input_boolean
end

#preferred?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/gedcomx/name.rb', line 96

def preferred?
  @name.get_preferred
end

#to_javaObject



122
123
124
# File 'lib/gedcomx/name.rb', line 122

def to_java
  @name
end

#typeObject



114
115
116
# File 'lib/gedcomx/name.rb', line 114

def type
  @name.get_type.to_s
end

#type=(input_type) ⇒ Object



118
119
120
# File 'lib/gedcomx/name.rb', line 118

def type=(input_type)
  @name.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type)
end