Class: Org::Familysearch::Ws::Familytree::V2::Schema::NameForm

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-fs-stack/enunciate/familytree.rb,
lib/ruby-fs-stack/familytree/name.rb

Overview

A name form.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fullTextObject

The normalized full text of the name.



847
848
849
# File 'lib/ruby-fs-stack/enunciate/familytree.rb', line 847

def fullText
  @fullText
end

#piecesObject

The name pieces.



849
850
851
# File 'lib/ruby-fs-stack/enunciate/familytree.rb', line 849

def pieces
  @pieces
end

#scriptObject

The name form script.



851
852
853
# File 'lib/ruby-fs-stack/enunciate/familytree.rb', line 851

def script
  @script
end

#selectedObject

true, if the segmentation is user selected.



853
854
855
# File 'lib/ruby-fs-stack/enunciate/familytree.rb', line 853

def selected
  @selected
end

Class Method Details

.from_json(o) ⇒ Object

constructs a NameForm from a (parsed) JSON hash



887
888
889
890
891
892
893
894
895
# File 'lib/ruby-fs-stack/enunciate/familytree.rb', line 887

def self.from_json(o)
  if o.nil?
    return nil
  else
    inst = new
    inst.init_jaxb_json_hash o
    return inst
  end
end

Instance Method Details

#buildFullTextObject



38
39
40
41
42
43
44
# File 'lib/ruby-fs-stack/familytree/name.rb', line 38

def buildFullText
  if self.pieces.nil?
    return ''
  else
    self.pieces.collect{|piece| "#{piece.predelimiters}#{piece.value}#{piece.postdelimiters}"}.join('')
  end
end

#init_jaxb_json_hash(_o) ⇒ Object

initializes this NameForm with a json hash



875
876
877
878
879
880
881
882
883
884
# File 'lib/ruby-fs-stack/enunciate/familytree.rb', line 875

def init_jaxb_json_hash(_o)
  @fullText = String.from_json(_o['fullText']) unless _o['fullText'].nil?
  if !_o['pieces'].nil?
    @pieces = Array.new
    _oa = _o['pieces']
    _oa.each { | _item | @pieces.push Org::Familysearch::Ws::Familytree::V2::Schema::NamePiece.from_json(_item) }
  end
  @script = String.from_json(_o['script']) unless _o['script'].nil?
  @selected = Boolean.from_json(_o['selected']) unless _o['selected'].nil?
end

#set_name(name) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ruby-fs-stack/familytree/name.rb', line 4

def set_name(name)
  split_pieces = name.match(/(.*)\/(.*)\//)
  # if there is a name like John Jacob /Felch/, split to name pieces, otherwise use fullText
  if split_pieces
    given_pieces = split_pieces[1]
    family_pieces = split_pieces[2]
    self.pieces = given_pieces.split(" ").collect do |piece|
      p = NamePiece.new
      p.type = "Given"
      p.postdelimiters = " "
      p.value = piece
      p
    end
    self.pieces = self.pieces + family_pieces.split(" ").collect do |piece|
      p = NamePiece.new
      p.type = "Family"
      p.predelimiters = ""
      p.value = piece
      p
    end
  else
    self.fullText = name
  end
end

#surnameObject



29
30
31
32
33
34
35
36
# File 'lib/ruby-fs-stack/familytree/name.rb', line 29

def surname
  if self.pieces.nil?
    (self.fullText.nil?) ? nil : self.fullText.split(' ').last
  else
    piece = self.pieces.find{|piece|piece.type == 'Family'}
    (piece.nil?) ? nil : piece.value
  end
end

#to_jaxb_json_hashObject

the json hash for this NameForm



856
857
858
859
860
861
862
863
864
865
866
867
# File 'lib/ruby-fs-stack/enunciate/familytree.rb', line 856

def to_jaxb_json_hash
  _h = {}
  _h['fullText'] = fullText.to_jaxb_json_hash unless fullText.nil?
  if !pieces.nil?
    _ha = Array.new
    pieces.each { | _item | _ha.push _item.to_jaxb_json_hash }
    _h['pieces'] = _ha
  end
  _h['script'] = script.to_jaxb_json_hash unless script.nil?
  _h['selected'] = selected.to_jaxb_json_hash unless selected.nil?
  return _h
end

#to_jsonObject

the json (string form) for this NameForm



870
871
872
# File 'lib/ruby-fs-stack/enunciate/familytree.rb', line 870

def to_json
  to_jaxb_json_hash.to_json
end