Class: Pipl::Name

Inherits:
Field
  • Object
show all
Defined in:
lib/pipl/fields.rb

Instance Attribute Summary collapse

Attributes inherited from Field

#current, #inferred, #last_seen, #valid_since

Instance Method Summary collapse

Methods inherited from Field

base_params_from_hash, extra_metadata, from_hash

Methods included from Utils

alnum_chars, alpha_chars, date_to_str, extract_rate_limits, is_valid_url?, str_to_date, titleize, to_utf8

Constructor Details

#initialize(params = {}) ⇒ Name

Returns a new instance of Name.



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/pipl/fields.rb', line 72

def initialize(params={})
  super params
  @first = params[:first]
  @middle = params[:middle]
  @last = params[:last]
  @prefix = params[:prefix]
  @suffix = params[:suffix]
  @type = params[:type]
  @raw = params[:raw]
  @display = params[:display]
end

Instance Attribute Details

#displayObject

Returns the value of attribute display.



70
71
72
# File 'lib/pipl/fields.rb', line 70

def display
  @display
end

#firstString

Returns First name.

Returns:

  • (String)

    First name



70
71
72
# File 'lib/pipl/fields.rb', line 70

def first
  @first
end

#lastString

Returns Last name.

Returns:

  • (String)

    Last name



70
# File 'lib/pipl/fields.rb', line 70

attr_accessor :first, :middle, :last, :prefix, :suffix, :type, :raw, :display

#middleString

Returns Middle name or initial.

Returns:

  • (String)

    Middle name or initial



70
# File 'lib/pipl/fields.rb', line 70

attr_accessor :first, :middle, :last, :prefix, :suffix, :type, :raw, :display

#prefixString

Returns Name prefix.

Returns:

  • (String)

    Name prefix



70
# File 'lib/pipl/fields.rb', line 70

attr_accessor :first, :middle, :last, :prefix, :suffix, :type, :raw, :display

#rawObject

Returns the value of attribute raw.



70
71
72
# File 'lib/pipl/fields.rb', line 70

def raw
  @raw
end

#suffixString

Returns Name suffix.

Returns:

  • (String)

    Name suffix



70
# File 'lib/pipl/fields.rb', line 70

attr_accessor :first, :middle, :last, :prefix, :suffix, :type, :raw, :display

#typeString

Returns Type of association of this name to a person. One of ‘present`, `maiden`, `former` or `alias`.

Returns:

  • (String)

    Type of association of this name to a person. One of ‘present`, `maiden`, `former` or `alias`.



70
# File 'lib/pipl/fields.rb', line 70

attr_accessor :first, :middle, :last, :prefix, :suffix, :type, :raw, :display

Instance Method Details

#is_searchable?Boolean

Returns:

  • (Boolean)


89
90
91
92
93
94
# File 'lib/pipl/fields.rb', line 89

def is_searchable?
  first = Pipl::Utils.alpha_chars(@first || '')
  last = Pipl::Utils.alpha_chars(@last || '')
  raw = Pipl::Utils.alpha_chars(@raw || '')
  first.length > 0 || last.length > 0 || raw.length > 0
end

#to_hashObject



84
85
86
87
# File 'lib/pipl/fields.rb', line 84

def to_hash
  {first: @first, middle: @middle, last: @last, prefix: @prefix, suffix: @suffix, raw: @raw}
      .reject { |_, value| value.nil? }
end

#to_sObject



96
97
98
99
100
101
102
# File 'lib/pipl/fields.rb', line 96

def to_s
  return @display if @display

  vals = [@prefix, @first, @middle, @last, @suffix]
  s = vals.any? ? vals.select { |v| v }.map { |v| v.capitalize }.join(' ') : nil
  s ? Pipl::Utils.to_utf8(s) : ''
end