Class: HumanName::Name
- Inherits:
-
FFI::AutoPointer
- Object
- FFI::AutoPointer
- HumanName::Name
- Defined in:
- lib/humanname.rb
Constant Summary collapse
- DESTRUCTOR =
Native.method(:human_name_free_name)
- JSON_PARTS =
%w( surname given_name first_initial middle_initials middle_names generational_suffix ).map(&:to_sym)
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #as_json(options = {}) ⇒ Object
- #goes_by_middle_name ⇒ Object
- #hash ⇒ Object
-
#initialize(pointer) ⇒ Name
constructor
A new instance of Name.
- #inspect ⇒ Object
- #length ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(pointer) ⇒ Name
Returns a new instance of Name.
103 104 105 |
# File 'lib/humanname.rb', line 103 def initialize(pointer) super(pointer, DESTRUCTOR) end |
Class Method Details
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
107 108 109 |
# File 'lib/humanname.rb', line 107 def ==(other) other.is_a?(Name) && Native.human_name_consistent_with(self, other) end |
#as_json(options = {}) ⇒ Object
135 136 137 138 139 140 141 142 143 |
# File 'lib/humanname.rb', line 135 def as_json( = {}) # We take an "options" argument for minimal compatibility with ActiveSupport, # but don't actually respect it [:root, :only, :except, :include].each do |opt| raise ArgumentError.new("Unsupported option: #{opt}") if [opt] end to_h end |
#goes_by_middle_name ⇒ Object
125 126 127 |
# File 'lib/humanname.rb', line 125 def goes_by_middle_name Native.human_name_goes_by_middle_name(self) end |
#hash ⇒ Object
112 113 114 |
# File 'lib/humanname.rb', line 112 def hash Native.human_name_hash(self) end |
#inspect ⇒ Object
152 153 154 |
# File 'lib/humanname.rb', line 152 def inspect "HumanName::Name(#{display_full})" end |
#length ⇒ Object
129 130 131 |
# File 'lib/humanname.rb', line 129 def length Native.human_name_byte_len(self) end |
#to_h ⇒ Object
145 146 147 148 149 150 |
# File 'lib/humanname.rb', line 145 def to_h JSON_PARTS.inject({}) do |memo, part| memo[part] = send(part) memo end end |