gedcomx-jruby 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ module Gedcomx
2
+ class FieldValue
3
+
4
+ def self.java_class
5
+ Java::OrgGedcomxRecords::FieldValue
6
+ end
7
+
8
+ def initialize(input = nil)
9
+ @value = input || self.class.java_class.new
10
+ end
11
+
12
+ def text
13
+ @value.get_text
14
+ end
15
+
16
+ def text=(input_string)
17
+ @value.text= input_string
18
+ end
19
+
20
+ def type
21
+ @value.get_type.to_s
22
+ end
23
+
24
+ def type= (input_type)
25
+ @value.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type)
26
+ end
27
+
28
+ def to_java
29
+ @value
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ module Gedcomx
2
+ class Gender
3
+
4
+ attr_reader :fields
5
+
6
+ def self.java_class
7
+ Java::OrgGedcomxConclusion::Gender
8
+ end
9
+
10
+ def self.create(attributes = {})
11
+ new_gender = self.new
12
+ new_gender.type = attributes[:type] if attributes[:type]
13
+ attributes[:fields].each { |field| new_gender.add_field(field) } if attributes[:fields].is_a? Array
14
+ new_gender
15
+ end
16
+
17
+ def self.create_male
18
+ new_gender = self.new
19
+ new_gender.type = Gedcomx::TYPES[:male]
20
+ field = Gedcomx::Field.create( values: [ { text: 'Male', type: Gedcomx::TYPES[:original] } ],
21
+ type: Gedcomx::TYPES[:gender] )
22
+ new_gender.add_field(field)
23
+ new_gender
24
+ end
25
+
26
+ def self.create_female
27
+ new_gender = self.new
28
+ new_gender.type = Gedcomx::TYPES[:female]
29
+ field = Gedcomx::Field.create( values: [ { text: 'Female', type: Gedcomx::TYPES[:original] } ],
30
+ type: Gedcomx::TYPES[:gender] )
31
+ new_gender.add_field(field)
32
+ new_gender
33
+ end
34
+
35
+ def initialize(input = nil)
36
+ @gender = input || self.class.java_class.new
37
+ @fields = []
38
+ @fields = @gender.fields.map { |field| Gedcomx::Field.new(field) } if @gender.fields.is_a? Array
39
+ end
40
+
41
+ def add_field(field)
42
+ return false unless field.is_a? Gedcomx::Field
43
+ @gender.add_field field.to_java
44
+ @fields << field
45
+ end
46
+
47
+ def type
48
+ @gender.get_type.to_s
49
+ end
50
+
51
+ def type= (input_type)
52
+ @gender.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type)
53
+ end
54
+
55
+ def to_java
56
+ @gender
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,39 @@
1
+ module Gedcomx
2
+ class Identifier
3
+
4
+ def self.java_class
5
+ Java::OrgGedcomxConclusion::Identifier
6
+ end
7
+
8
+ def self.create(attributes = {})
9
+ new_identifier = self.new
10
+ new_identifier.type = attributes[:type] if attributes[:type]
11
+ new_identifier.value = attributes[:value] if attributes[:value]
12
+ new_identifier
13
+ end
14
+
15
+ def initialize(input = nil)
16
+ @identifier = input || self.class.java_class.new
17
+ end
18
+
19
+ def type
20
+ @identifier.get_type.to_s
21
+ end
22
+
23
+ def type=(input_type)
24
+ @identifier.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type)
25
+ end
26
+
27
+ def value
28
+ @identifier.get_value.to_s
29
+ end
30
+
31
+ def value=(input_value)
32
+ @identifier.value = ( input_value.is_a? Gedcomx.java_uri_class ) ? input_value : Gedcomx.new_uri(input_value)
33
+ end
34
+
35
+ def to_java
36
+ @identifier
37
+ end
38
+ end
39
+ end
@@ -2,6 +2,9 @@
2
2
  module Gedcomx
3
3
  class Iterator
4
4
  def initialize(input)
5
+ unless File.file?(input)
6
+ input = Gedcomx.input_stream(input)
7
+ end
5
8
  @iter = org.gedcomx.util.RecordSetIterator.new(input)
6
9
  end
7
10
 
@@ -16,5 +19,9 @@ module Gedcomx
16
19
  def next
17
20
  Record.new(@iter.next)
18
21
  end
22
+
23
+ def to_java
24
+ @iter
25
+ end
19
26
  end
20
27
  end
@@ -1,5 +1,5 @@
1
1
  module Gedcomx
2
2
  module Jruby
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -0,0 +1,133 @@
1
+ module Gedcomx
2
+ class Name
3
+
4
+ attr_reader :date, :forms
5
+
6
+ def self.java_class
7
+ Java::OrgGedcomxConclusion::Name
8
+ end
9
+
10
+ def self.build_simple(attributes = {})
11
+ first = attributes[:first]
12
+ last = attributes[:last]
13
+ name_form = Gedcomx::NameForm.new
14
+ name_form.full_text = attributes[:full] if attributes[:full]
15
+
16
+ if first
17
+ field = Gedcomx::Field.create( first_attributes = {
18
+ values: [ { text: first, type: Gedcomx::TYPES[:original] } ],
19
+ type: Gedcomx::TYPES[:given]
20
+ } )
21
+
22
+ name_part = Gedcomx::NamePart.create( first_attributes = {
23
+ fields: [ field ],
24
+ value: first,
25
+ type: Gedcomx::TYPES[:given]
26
+ })
27
+
28
+ name_form.add_part(name_part)
29
+ end
30
+
31
+ if last
32
+ field = Gedcomx::Field.create( last_attributes = {
33
+ values: [ { text: last, type: Gedcomx::TYPES[:original] } ],
34
+ type: Gedcomx::TYPES[:surname]
35
+ } )
36
+
37
+ name_part = Gedcomx::NamePart.create( last_attributes = {
38
+ fields: [ field ],
39
+ value: last,
40
+ type: Gedcomx::TYPES[:surname]
41
+ })
42
+
43
+ name_form.add_part(name_part)
44
+ end
45
+
46
+ attributes[:forms] = [name_form]
47
+ self.create(attributes)
48
+ end
49
+
50
+ def self.create(attributes = {})
51
+ new_name = self.new
52
+ new_name.confidence = attributes[:confidence] if attributes[:confidence]
53
+ new_name.preferred = attributes[:preferred] if attributes[:preferred]
54
+ new_name.language = attributes[:language] if attributes[:language]
55
+ new_name.type = attributes[:type] if attributes[:type]
56
+
57
+ if attributes[:type]
58
+ puts attributes[:type]
59
+ end
60
+
61
+ attributes[:forms].each { |form| new_name.add_form(form) } if attributes[:forms].is_a? Array
62
+ new_name
63
+ end
64
+
65
+ def initialize(input = nil)
66
+ @name = input || self.class.java_class.new
67
+ @date = Gedcomx::Date.new(@name.get_date) if @name.get_date
68
+ @forms = []
69
+ @forms = @name.get_name_forms.map { |form| Gedcomx::NameForm.new(form) } if @name.get_name_forms
70
+ end
71
+
72
+ def add_form(form)
73
+ return false unless form.is_a? Gedcomx::NameForm
74
+ @name.add_name_form form.to_java
75
+ @forms << form
76
+ end
77
+
78
+ def date=(date)
79
+ return false unless date.is_a? Gedcomx::Date
80
+ @name.date = date.to_java
81
+ @date = date
82
+ end
83
+
84
+ def confidence
85
+ @name.get_confidence
86
+ end
87
+
88
+ def confidence=(input_confidence)
89
+ if input_confidence.is_a? Gedcomx.java_uri_class
90
+ @name.confidence = input_confidence
91
+ else
92
+ @name.confidence = Gedcomx.new_uri(input_confidence)
93
+ end
94
+ end
95
+
96
+ def preferred?
97
+ @name.get_preferred
98
+ end
99
+
100
+ def preferred=(input_boolean)
101
+ return false unless input_boolean.is_a? Boolean
102
+ @name.preferred = input_boolean
103
+ end
104
+
105
+ def language
106
+ @name.get_lang
107
+ end
108
+
109
+ def language=(input_language)
110
+ return false unless input_language.is_a? String
111
+ @name.lang = input_language
112
+ end
113
+
114
+ def type
115
+ @name.get_type.to_s
116
+ end
117
+
118
+ def type=(input_type)
119
+ @name.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type)
120
+ end
121
+
122
+ def to_java
123
+ @name
124
+ end
125
+
126
+ # Generates accessor methods for each of the types
127
+ TYPES.keys.each do |type|
128
+ define_method type do
129
+ first_value(type)
130
+ end
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,41 @@
1
+ module Gedcomx
2
+ class NameForm
3
+
4
+ attr_reader :parts
5
+
6
+ def self.java_class
7
+ Java::OrgGedcomxConclusion::NameForm
8
+ end
9
+
10
+ def self.create(attributes = {})
11
+ new_form = self.new
12
+ new_form.full_text = attributes[:full_text] if attributes[:full_text]
13
+ attributes[:fields].each { |field| new_form.add_field field } if attributes[:fields].is_a? Array
14
+ attributes[:parts].each { |part| new_form.add_part part } if attributes[:parts].is_a? Array
15
+ end
16
+
17
+ def initialize(input = nil)
18
+ @name_form = input || self.class.java_class.new
19
+ @parts = []
20
+ @parts = @name_form.parts.map { |part| Gedcomx::NamePart.new(part) } if @name_form.parts
21
+ end
22
+
23
+ def add_part(part)
24
+ return false unless part.is_a? Gedcomx::NamePart
25
+ @name_form.add_part part.to_java
26
+ @parts << part
27
+ end
28
+
29
+ def full_text
30
+ @name_form.get_full_text
31
+ end
32
+
33
+ def full_text=(full_text)
34
+ @name_form.full_text = full_text
35
+ end
36
+
37
+ def to_java
38
+ @name_form
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,50 @@
1
+ module Gedcomx
2
+ class NamePart
3
+
4
+ attr_reader :fields
5
+
6
+ def self.java_class
7
+ Java::OrgGedcomxConclusion::NamePart
8
+ end
9
+
10
+ def self.create(attributes = {})
11
+ new_part = self.new
12
+ new_part.value = attributes[:value] if attributes[:value]
13
+ new_part.type = attributes[:type] if attributes[:type]
14
+ attributes[:fields].each { |field| new_part.add_field field } if attributes[:fields].is_a? Array
15
+ new_part
16
+ end
17
+
18
+ def initialize(input = nil)
19
+ @name_part = input || self.class.java_class.new
20
+ @fields = []
21
+ @fields = @name_part.fields.map { |field| Gedcomx::Field.new(field) } if @name_part.fields
22
+ end
23
+
24
+ def add_field(field)
25
+ return false unless field.is_a? Gedcomx::Field
26
+ @name_part.to_java.add_field field.to_java
27
+ @fields << field
28
+ end
29
+
30
+ def type
31
+ @name_part.get_type.to_s
32
+ end
33
+
34
+ def type=(input_type)
35
+ @name_part.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type)
36
+ end
37
+
38
+ def value
39
+ @name_part.get_value
40
+ end
41
+
42
+ def value=(input_value)
43
+ @name_part.value = input_value
44
+ end
45
+
46
+ def to_java
47
+ @name_part
48
+ end
49
+ end
50
+ end
@@ -1,9 +1,34 @@
1
1
  module Gedcomx
2
-
3
2
  class Person
4
3
 
5
- def initialize(input)
6
- @person = input
4
+ attr_reader :names, :fields, :facts, :identifiers, :gender
5
+
6
+ def self.java_class
7
+ Java::OrgGedcomxConclusion::Person
8
+ end
9
+
10
+ def self.create(attributes = {})
11
+ new_person = self.new
12
+ new_person.principal = attributes[:principal] if attributes[:principal]
13
+ new_person.relative_id = attributes[:relative_id] if attributes[:relative_id]
14
+ attributes[:fields].each { |field| new_person.add_field(field) } if attributes[:fields].is_a? Array
15
+ attributes[:facts].each { |fact| new_person.add_fact(fact) } if attributes[:facts].is_a? Array
16
+ attributes[:names].each { |name| new_person.add_name(name) } if attributes[:names].is_a? Array
17
+ attributes[:identifiers].each { |id| new_person.add_identifier(id) } if attributes[:identifiers].is_a? Array
18
+ new_person
19
+ end
20
+
21
+ def initialize(input = nil)
22
+ @person = input || self.class.java_class.new
23
+ @gender = Gedcomx::Gender.new(@person.get_gender) if @person.get_gender
24
+ @identifiers = []
25
+ @identifiers = @person.identifiers.map { |identifier| Gedcomx::Identifier.new(identifier) } if @person.identifiers
26
+ @names = []
27
+ @names = @person.names.map { |name| Gedcomx::Name.new(name) } if @person.names
28
+ @facts = []
29
+ @facts = @person.facts.map { |fact| Gedcomx::Fact.new(fact) } if @person.facts
30
+ @fields = []
31
+ @fields = @person.fields.map { |field| Gedcomx::Field.new(field) } if @person.fields
7
32
  end
8
33
 
9
34
  def male?
@@ -16,24 +41,198 @@ module Gedcomx
16
41
  gender == TYPES[:female]
17
42
  end
18
43
 
19
- def gender
20
- return TYPES[:male] if self.male?
21
- TYPES[:female] if self.female?
44
+ def gender_type
45
+ return TYPES[:male] if male?
46
+ TYPES[:female] if female?
47
+ end
48
+
49
+ def set_gender(gender)
50
+ return false unless gender.is_a? Gedcomx::Gender
51
+ @person.gender = gender.to_java
52
+ @gender = gender
53
+ end
54
+
55
+ def set_gender_male
56
+ set_gender(Gedcomx::Gender.create_male)
57
+ end
58
+
59
+ def set_gender_female
60
+ set_gender(Gedcomx::Gender.create_female)
22
61
  end
23
62
 
24
63
  # Returns a list of name hashes
25
- def names
64
+ def names_hash
26
65
  names_list = []
27
66
  @person.names.each do |name_obj|
28
67
  name_obj.name_forms.each do |name_form_obj|
29
68
  name_hash = {}
30
69
  name_hash[:full] = name_form_obj.get_full_text
31
- name_hash[:first] = name_form_obj.parts.find{|part| part.get_type.to_s == TYPES[:given] }.andand.get_value
32
- name_hash[:last] = name_form_obj.parts.find{|part| part.get_type.to_s == TYPES[:surname] }.andand.get_value
70
+ first_name = name_form_obj.parts.find{|part| part.get_type.to_s == TYPES[:given] }
71
+ unless first_name.nil?
72
+ name_hash[:first] = first_name.get_value
73
+ end
74
+ last_name = name_form_obj.parts.find{|part| part.get_type.to_s == TYPES[:surname] }
75
+ unless last_name.nil?
76
+ name_hash[:last] = last_name.get_value
77
+ end
33
78
  names_list << name_hash
34
79
  end
35
80
  end
36
81
  names_list
37
82
  end
83
+
84
+ def add_fact(fact)
85
+ return false unless fact.is_a? Gedcomx::Fact
86
+ @person.add_fact(fact.to_java)
87
+ @facts << fact
88
+ end
89
+
90
+ def add_field(field)
91
+ return false unless field.is_a? Gedcomx::Field
92
+ @person.add_field(field.to_java)
93
+ @fields << field
94
+ end
95
+
96
+ def add_identifier(identifier)
97
+ return false unless identifier.is_a? Gedcomx::Identifier
98
+ @person.add_identifier identifier.to_java
99
+ @identifiers << identifier
100
+ end
101
+
102
+ def add_name(name)
103
+ return false unless name.is_a? Gedcomx::Name
104
+ @person.add_name name.to_java
105
+ @names << name
106
+ end
107
+
108
+ def add_birthday(info = {})
109
+ birth_date = Gedcomx::Date.create_simple(info)
110
+ birth_fact = Gedcomx::Fact.create(date: birth_date, type: Gedcomx::TYPES[:birth])
111
+ add_fact(birth_fact)
112
+ end
113
+
114
+ def principal?
115
+ @person.get_principal
116
+ end
117
+
118
+ def principal=(input_boolean)
119
+ return false unless input_boolean.is_a? Boolean
120
+ @person.principal = input_boolean
121
+ end
122
+
123
+ def event_date
124
+ primary_fact = self.primary_fact
125
+ unless primary_fact.nil?
126
+ primary_date = primary_fact.get_date
127
+ return get_date(primary_date) unless primary_date.nil?
128
+ end
129
+ end
130
+
131
+ def birth_date
132
+ birthday_obj = Gedcomx.get_first_fact(@person, :birth)
133
+ unless birthday_obj.nil?
134
+ birth_date_obj = birthday_obj.get_date
135
+ get_date(birth_date_obj)
136
+ end
137
+ end
138
+
139
+ def first_value(type)
140
+ field = Gedcomx.get_first_field(@person, type)
141
+ unless field.nil?
142
+ interpreted = Gedcomx.interpreted_value(field)
143
+ return interpreted.get_text unless interpreted.nil?
144
+ return nil
145
+ end
146
+ fact = Gedcomx.get_first_fact(@person, type)
147
+ unless fact.nil?
148
+ fact.get_value
149
+ end
150
+ end
151
+
152
+ def location
153
+ primary_fact = @person.facts.find{|fact| fact.get_primary }
154
+
155
+ location = primary_fact.get_place
156
+ location_params = {}
157
+ location_params[:name] = location.get_original
158
+
159
+ # Fill in the location level definitions
160
+ location_levels = {}
161
+ location_fields = @person.fields.select{|field| field.get_type.to_s.include? 'EVENT_PLACE_LEVEL_' }
162
+ location_fields.each do |field|
163
+ value = field.get_values[0].get_text
164
+ level = /EVENT_PLACE_LEVEL_\d/.match(field.get_type.to_s)[0]
165
+ location_levels[level] = value
166
+ end
167
+
168
+ # Match the location name to the appropriate level
169
+ location.get_fields.each do |field|
170
+ value = Gedcomx.interpreted_value(field)
171
+
172
+ # Store the level if it is valid
173
+ level = location_levels[value.label_id]
174
+ next if level.nil?
175
+ mapped_value = Gedcomx.location_mapping(level)
176
+ next if mapped_value.nil?
177
+ location_params[mapped_value] = value.get_text
178
+ end
179
+
180
+ location_params
181
+ end
182
+
183
+ def relative_id
184
+ @person.get_id
185
+ end
186
+
187
+ def relative_id=(id_string)
188
+ return false unless id_string.is_a? String
189
+ @person.id = id_string
190
+ end
191
+
192
+ def to_java
193
+ @person
194
+ end
195
+
196
+ # Generates accessor methods for each of the types
197
+ TYPES.keys.each do |type|
198
+ define_method type do
199
+ first_value(type)
200
+ end
201
+ end
202
+
203
+ def gender
204
+ @gender
205
+ end
206
+
207
+ protected
208
+
209
+ def method_missing(something)
210
+ @person.send(something)
211
+ end
212
+
213
+ def primary_fact
214
+ @person.facts.find{|fact| fact.get_primary }
215
+ end
216
+
217
+ def get_date(date_obj)
218
+ date_hash = {}
219
+ year_field = Gedcomx.interpreted_value( Gedcomx.get_first_field(date_obj, :year) )
220
+ unless year_field.nil?
221
+ year = year_field.get_text.to_i
222
+ date_hash[:year] = year
223
+ end
224
+ month_field = Gedcomx.interpreted_value( Gedcomx.get_first_field(date_obj, :month) )
225
+ unless month_field.nil?
226
+ month = month_field.get_text
227
+ month = MONTH_MAP[month.downcase.to_sym] unless month.nil?
228
+ date_hash[:month] = month
229
+ end
230
+ day_field = Gedcomx.interpreted_value( Gedcomx.get_first_field(date_obj, :day) )
231
+ unless day_field.nil?
232
+ day = day_field.get_text
233
+ date_hash[:day] = day
234
+ end
235
+ date_hash
236
+ end
38
237
  end
39
238
  end