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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 40adac85b323407e4921e797c0264d08a7f3ff6f
4
- data.tar.gz: 80988d457e366c411415cbcb319d40115f11e741
3
+ metadata.gz: 6b9e69b76c9d0b2f926c4f5694770037c1071d43
4
+ data.tar.gz: c69d674c3a8f8d8a946deea6d8e5c4f96d5ba3dd
5
5
  SHA512:
6
- metadata.gz: 2275a81a7cc9c85aa40f71639237c66934037044b9ff4b7beed535d49c609c4a37bbf02edc200767b1e298f56b57fb04588c6b2028d744043f2b33950537b797
7
- data.tar.gz: a889704e22047d71efe1c7e3956ba4fc155b4357026eb986a465205f3af319aff609f5ce6e4198eb6a1f4cdb33576581a0bde0deb17452d82d032996a6af4751
6
+ metadata.gz: 1ca5af3fbb72f42b7302bda9925966101650fd1ffcfe18cd056ce7b23079ed3aa8c113a13371ee1f96561bf97e2380f34c55d51f15ea32524347067d926bc96c
7
+ data.tar.gz: 37c8052cce26bdf8006ca639eb7b14812ae0a2099a354ecceb449da84125ef2e60107730868bde9d8bee2174a22a9f1337c5e2229e2751dd9b2cbb2c3646dfea
data/Gemfile CHANGED
@@ -2,5 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in gedcomx-jruby.gemspec
4
4
  gemspec
5
-
6
- gem 'andand'
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Gedcomx::Jruby
2
2
 
3
- TODO: Write a gem description
3
+ Ruby gem that allows for iterating through GedcomX files
4
4
 
5
5
  ## Installation
6
6
 
@@ -16,9 +16,9 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install gedcomx-jruby
18
18
 
19
- ## Usage
19
+ Note : This gem can only run on JRuby
20
20
 
21
- TODO: Write usage instructions here
21
+ ## Usage
22
22
 
23
23
  ## Contributing
24
24
 
@@ -2,10 +2,6 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'gedcomx/jruby/version'
5
- require 'gedcomx/gedcomx'
6
- require 'gedcomx/iterator'
7
- require 'gedcomx/record'
8
- require 'gedcomx/person'
9
5
 
10
6
  Gem::Specification.new do |spec|
11
7
  spec.name = "gedcomx-jruby"
@@ -0,0 +1 @@
1
+ require 'gedcomx'
@@ -0,0 +1,181 @@
1
+ require "gedcomx/jruby/version"
2
+
3
+ module Gedcomx
4
+ TYPES = {
5
+ age: 'http://gedcomx.org/Age',
6
+ birth: 'http://gedcomx.org/Birth',
7
+ birth_name: 'http://gedcomx.org/BirthName',
8
+ birth_place_father: 'http://gedcomx.org/FatherBirthPlace',
9
+ birth_place_mother: 'http://gedcomx.org/MotherBirthPlace',
10
+ census: 'http://gedcomx.org/Census',
11
+ collection: 'http://gedcomx.org/Collection',
12
+ collection_id: 'http://familysearch.org/types/fields/FS_COLLECTION_ID',
13
+ couple: 'http://gedcomx.org/Couple',
14
+ date: 'http://gedcomx.org/Date',
15
+ day: 'http://gedcomx.org/Day',
16
+ digital_artifact: 'http://gedcomx.org/DigitalArtifact',
17
+ ethnicity: 'http://familysearch.org/types/fields/PR_ETHNICITY_CSS',
18
+ event_city: 'http://familysearch.org/types/fields/EVENT_TOWNSHIP',
19
+ event_country: 'http://familysearch.org/types/fields/EVENT_COUNTRY',
20
+ event_county: 'http://familysearch.org/types/fields/EVENT_COUNTY',
21
+ event_district: 'http://familysearch.org/types/fields/EVENT_DISTRICT',
22
+ event_state: 'http://familysearch.org/types/fields/EVENT_STATE',
23
+ event_type: 'http://familysearch.org/types/fields/EVENT_TYPE',
24
+ female: 'http://gedcomx.org/Female',
25
+ film_number: 'http://familysearch.org/types/fields/FILM_NUMBER',
26
+ folder: 'http://familysearch.org/types/fields/FOLDER',
27
+ folder_image_seq: 'http://familysearch.org/types/fields/FOLDER_IMAGE_SEQ',
28
+ gender: 'http://gedcomx.org/Gender',
29
+ given: 'http://gedcomx.org/Given',
30
+ household: 'http://familysearch.org/types/fields/HOUSEHOLD_ID',
31
+ image_apid: 'http://familysearch.org/types/fields/IMAGE_APID',
32
+ image_id: 'http://familysearch.org/types/fields/IMAGE_PAL',
33
+ image_number: 'http://familysearch.org/types/fields/IMAGE_NBR',
34
+ image_pal: 'http://familysearch.org/types/fields/IMAGE_PAL',
35
+ immigration: 'http://gedcomx.org/Immigration',
36
+ interpreted: 'http://gedcomx.org/Interpreted',
37
+ male: 'http://gedcomx.org/Male',
38
+ marital_status: 'http://gedcomx.org/MaritalStatus',
39
+ month: 'http://gedcomx.org/Month',
40
+ name: 'http://gedcomx.org/Name',
41
+ original: 'http://gedcomx.org/Original',
42
+ parent_child: 'http://gedcomx.org/ParentChild',
43
+ persistent: 'http://gedcomx.org/Persistent',
44
+ race: 'http://gedcomx.org/Race',
45
+ record: 'http://gedcomx.org/Record',
46
+ record_group: 'http://familysearch.org/types/fields/RECORD_GROUP',
47
+ relation_to_head: 'http://gedcomx.org/RelationshipToHead',
48
+ source_line: 'http://familysearch.org/types/fields/SOURCE_LINE_NBR',
49
+ source_sheet: 'http://familysearch.org/types/fields/SOURCE_SHEET_NBR_LTR',
50
+ source_sheet_letter: 'http://familysearch.org/types/fields/SOURCE_SHEET_LTR',
51
+ source_sheet_number: 'http://familysearch.org/types/fields/SOURCE_SHEET_NBR',
52
+ surname: 'http://gedcomx.org/Surname',
53
+ unique_id: 'http://familysearch.org/types/fields/UNIQUE_IDENTIFIER',
54
+ year: 'http://gedcomx.org/Year',
55
+ years_married: 'http://familysearch.org/types/fields/PR_CNT_YEARS_MARR'
56
+ }
57
+ end
58
+
59
+ require 'gedcomx/writer'
60
+ require 'gedcomx/person'
61
+ require 'gedcomx/relationship'
62
+ require 'gedcomx/record'
63
+ require 'gedcomx/iterator'
64
+ require 'gedcomx/fact'
65
+ require 'gedcomx/field'
66
+ require 'gedcomx/field_value'
67
+ require 'gedcomx/name'
68
+ require 'gedcomx/name_part'
69
+ require 'gedcomx/name_form'
70
+ require 'gedcomx/date'
71
+ require 'gedcomx/place'
72
+ require 'gedcomx/gender'
73
+ require 'gedcomx/identifier'
74
+ require 'gedcomx/resource_reference'
75
+
76
+ # Load all the java jars
77
+ require "gedcomx_java_jars/enunciate-gedcomx-support-1.0.82.M1-SNAPSHOT-sources.jar"
78
+ require "gedcomx_java_jars/enunciate-gedcomx-support-1.0.82.M1-SNAPSHOT.jar"
79
+ require "gedcomx_java_jars/familysearch-api-client-1.0.82.M1-SNAPSHOT-sources.jar"
80
+ require "gedcomx_java_jars/familysearch-api-client-1.0.82.M1-SNAPSHOT.jar"
81
+ require "gedcomx_java_jars/familysearch-api-model-1.0.82.M1-SNAPSHOT-sources.jar"
82
+ require "gedcomx_java_jars/familysearch-api-model-1.0.82.M1-SNAPSHOT.jar"
83
+ require "gedcomx_java_jars/gedcomx-atom-1.0.82.M1-SNAPSHOT-sources.jar"
84
+ require "gedcomx_java_jars/gedcomx-atom-1.0.82.M1-SNAPSHOT.jar"
85
+ require "gedcomx_java_jars/gedcomx-date-1.0.82.M1-SNAPSHOT-sources.jar"
86
+ require "gedcomx_java_jars/gedcomx-date-1.0.82.M1-SNAPSHOT.jar"
87
+ require "gedcomx_java_jars/gedcomx-fileformat-1.0.82.M1-SNAPSHOT-sources.jar"
88
+ require "gedcomx_java_jars/gedcomx-fileformat-1.0.82.M1-SNAPSHOT.jar"
89
+ require "gedcomx_java_jars/gedcomx-model-1.0.82.M1-SNAPSHOT-sources.jar"
90
+ require "gedcomx_java_jars/gedcomx-model-1.0.82.M1-SNAPSHOT.jar"
91
+ require "gedcomx_java_jars/gedcomx-rs-client-1.0.82.M1-SNAPSHOT-sources.jar"
92
+ require "gedcomx_java_jars/gedcomx-rs-client-1.0.82.M1-SNAPSHOT.jar"
93
+ require "gedcomx_java_jars/gedcomx-rs-rt-support-1.0.82.M1-SNAPSHOT-sources.jar"
94
+ require "gedcomx_java_jars/gedcomx-rs-rt-support-1.0.82.M1-SNAPSHOT.jar"
95
+ require "gedcomx_java_jars/gedcomx-rt-support-1.0.82.M1-SNAPSHOT-sources.jar"
96
+ require "gedcomx_java_jars/gedcomx-rt-support-1.0.82.M1-SNAPSHOT.jar"
97
+ require "gedcomx_java_jars/gedcomx-test-support-1.0.82.M1-SNAPSHOT-sources.jar"
98
+ require "gedcomx_java_jars/gedcomx-test-support-1.0.82.M1-SNAPSHOT.jar"
99
+ require "gedcomx_java_jars/jaxb-all.osgi-2.1.6.jar"
100
+
101
+ module Gedcomx
102
+ MONTH_MAP = {
103
+ jan: 1,
104
+ feb: 2,
105
+ mar: 3,
106
+ apr: 4,
107
+ may: 5,
108
+ jun: 6,
109
+ jul: 7,
110
+ aug: 8,
111
+ sep: 9,
112
+ oct: 10,
113
+ nov: 11,
114
+ dec: 12
115
+ }
116
+
117
+ LOCATION_MAP = {
118
+ country: :country,
119
+ state: :state,
120
+ county: :region
121
+ }
122
+
123
+ def self.java_uri_class
124
+ Java::OrgGedcomxCommon::URI
125
+ end
126
+
127
+ def self.new_uri(uri_string)
128
+ self.java_uri_class.new(uri_string.to_s)
129
+ end
130
+
131
+ def self.get_facts(obj, type)
132
+ return unless obj
133
+ obj.facts.select{|fact| fact.get_type.to_s == TYPES[type] }
134
+ end
135
+
136
+ def self.get_first_fact(obj, type)
137
+ return unless obj
138
+ obj.facts.find{|fact| fact.get_type.to_s == TYPES[type] }
139
+ end
140
+
141
+ def self.get_fields(obj, type)
142
+ return unless obj
143
+ obj.fields.select{|field| field.get_type.to_s == TYPES[type] }
144
+ end
145
+
146
+ def self.get_first_field(obj, type)
147
+ return unless obj
148
+ obj.fields.find{|field| field.get_type.to_s == TYPES[type] }
149
+ end
150
+
151
+ def self.interpreted_value(field_obj)
152
+ return if field_obj.nil?
153
+ values = field_obj.get_values
154
+
155
+ # If more than 1 value exists, we will choose 'Interpreted'
156
+ if values.length > 1
157
+ value = values.select{|val| val.get_type.to_s.include? 'Interpreted' }.first
158
+ else
159
+ value = values[0]
160
+ end
161
+
162
+ return value
163
+ end
164
+
165
+ def self.location_mapping(key)
166
+ value = LOCATION_MAP[key.downcase.to_sym]
167
+ return value unless value.nil?
168
+ return :city if key.downcase.include? 'town'
169
+ end
170
+
171
+ def self.to_java_string(ruby_string)
172
+ java.lang.String.new(ruby_string)
173
+ end
174
+
175
+ def self.input_stream(ruby_string)
176
+ java.io.ByteArrayInputStream.new( to_java_string(ruby_string).getBytes )
177
+ end
178
+
179
+ end
180
+
181
+
@@ -0,0 +1,87 @@
1
+ module Gedcomx
2
+ class Date
3
+
4
+ attr_reader :fields
5
+
6
+ def self.java_class
7
+ Java::OrgGedcomxConclusion::Date
8
+ end
9
+
10
+ def self.create(attributes = {})
11
+ new_date = self.new
12
+ new_date.original = attributes[:original] if attributes[:original]
13
+ attributes[:fields].each { |field| new_date.add_field(field) } if attributes[:fields].is_a? Array
14
+ new_date
15
+ end
16
+
17
+ def self.create_simple(attributes = {})
18
+ day = attributes[:day]
19
+ month = attributes[:month]
20
+ year = attributes[:year]
21
+
22
+ return nil unless ( day || month || year )
23
+ new_fields = []
24
+ full_string = ''
25
+
26
+ if day
27
+ full_string += day
28
+ new_fields << Gedcomx::Field.create(values: [ { text: day, type: Gedcomx::TYPES[:day] } ])
29
+ end
30
+
31
+ if month
32
+ full_string += ' ' unless full_string.empty?
33
+ full_string += month
34
+ new_fields << Gedcomx::Field.create(values: [ { text: month, type: Gedcomx::TYPES[:month] } ])
35
+ end
36
+
37
+ if year
38
+ full_string += ' ' unless full_string.empty?
39
+ full_string += year
40
+ new_fields << Gedcomx::Field.create(values: [ { text: year, type: Gedcomx::TYPES[:year] } ])
41
+ end
42
+
43
+ new_fields << Gedcomx::Field.create(values: [ { text: full_string, type: Gedcomx::TYPES[:original] } ])
44
+ self.create(fields: new_fields)
45
+ end
46
+
47
+ def initialize(input = nil)
48
+ @date = input || self.class.java_class.new
49
+ @fields = []
50
+ @fields = @date.fields.map { |field| Gedcomx::Field.new(field) } if @date.fields
51
+ end
52
+
53
+ def day
54
+ day_field = @fields.select { |field| field.type == Gedcomx::TYPES[:day] }.first
55
+ day_field.values.first.text if day_field
56
+ end
57
+
58
+ def month
59
+ month_field = @fields.select { |field| field.type == Gedcomx::TYPES[:month] }.first
60
+ month_field.values.first.text if month_field
61
+ end
62
+
63
+ def year
64
+ year_field = @fields.select { |field| field.type == Gedcomx::TYPES[:year] }.first
65
+ year_field.values.first.text if year_field
66
+ end
67
+
68
+ def add_field(field)
69
+ return false unless field.is_a? Gedcomx::Field
70
+ @date.add_field field.to_java
71
+ @fields << field
72
+ end
73
+
74
+ def original
75
+ @date.original
76
+ end
77
+
78
+ def original=(input_string)
79
+ return false unless input_string.is_a? String
80
+ @date.original = input_string
81
+ end
82
+
83
+ def to_java
84
+ @date
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,69 @@
1
+ module Gedcomx
2
+ class Fact
3
+
4
+ attr_reader :date, :fields, :place
5
+
6
+ def self.java_class
7
+ Java::OrgGedcomxConclusion::Fact
8
+ end
9
+
10
+ def self.create(attributes = {})
11
+ new_fact = self.new
12
+ new_fact.date = attributes[:date] if attributes[:date]
13
+ new_fact.type = attributes[:type] if attributes[:type]
14
+ new_fact.value = attributes[:value] if attributes[:value]
15
+ new_fact.primary = attributes[:primary] if attributes[:primary]
16
+ attributes[:fields].each { |field| new_fact.add_field(field) } if attributes[:fields].is_a? Array
17
+ new_fact
18
+ end
19
+
20
+ def initialize(input = nil)
21
+ @fact = input || self.class.java_class.new
22
+ @date = Gedcomx::Date.new(@fact.get_date) if @fact.get_date
23
+ @place = Gedcomx::Place.new(@fact.get_place) if @fact.get_place
24
+ @fields = []
25
+ @fields = @fact.fields.map { |field| Gedcomx::Field.new(field) } if @fact.fields.is_a? Array
26
+ end
27
+
28
+ def add_field(field)
29
+ return false unless field.is_a? Gedcomx::Field
30
+ @fact.add_field field.to_java
31
+ @fact.fields << field
32
+ end
33
+
34
+ def date=(date)
35
+ return false unless date.is_a? Gedcomx::Date
36
+ @fact.date = date.to_java
37
+ @date = date
38
+ end
39
+
40
+ def primary?
41
+ @fact.get_primary
42
+ end
43
+
44
+ def primary=(is_primary)
45
+ return false unless is_primary.is_a? Boolean
46
+ @fact.primary = is_primary
47
+ end
48
+
49
+ def type
50
+ @fact.get_type.to_s
51
+ end
52
+
53
+ def type= (input_type)
54
+ @fact.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type)
55
+ end
56
+
57
+ def value
58
+ @fact.get_value
59
+ end
60
+
61
+ def value= (value_string)
62
+ @fact.value = value_string
63
+ end
64
+
65
+ def to_java
66
+ @fact
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,54 @@
1
+ module Gedcomx
2
+ class Field
3
+
4
+ attr_reader :values
5
+
6
+ def self.java_class
7
+ Java::OrgGedcomxRecords::Field
8
+ end
9
+
10
+ def self.java_value_class
11
+ Java::OrgGedcomxRecords::FieldValue
12
+ end
13
+
14
+ def self.create(attributes = {})
15
+ new_field = self.new
16
+ values = attributes[:values]
17
+
18
+ new_field.type = attributes[:type] if attributes[:type]
19
+ if values.is_a? Array
20
+ values.each do |value|
21
+ next unless value.is_a? Hash
22
+ new_field.add_value(value[:text], value[:type])
23
+ end
24
+ end
25
+ new_field
26
+ end
27
+
28
+ def initialize(input = nil)
29
+ @field = input || self.class.java_class.new
30
+ @values = []
31
+ @values = @field.values.map { |value| Gedcomx::FieldValue.new(value) } if @field.values
32
+ end
33
+
34
+ def add_value(value_string, input_type = nil)
35
+ value = Gedcomx::FieldValue.new
36
+ value.text = value_string
37
+ value.type = input_type if input_type
38
+ @field.add_value value.to_java
39
+ @values << value
40
+ end
41
+
42
+ def type
43
+ @field.get_type.to_s
44
+ end
45
+
46
+ def type=(input_type)
47
+ @field.type = ( input_type.is_a? Gedcomx.java_uri_class ) ? input_type : Gedcomx.new_uri(input_type)
48
+ end
49
+
50
+ def to_java
51
+ @field
52
+ end
53
+ end
54
+ end