Class: MelissaData::Server::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/melissadata/server/base.rb

Direct Known Subclasses

TCP, Unix

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



8
9
10
# File 'lib/melissadata/server/base.rb', line 8

def initialize
  @server = MessagePack::RPC::Server.new
end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



6
7
8
# File 'lib/melissadata/server/base.rb', line 6

def server
  @server
end

Instance Method Details

#address_objectObject



116
117
118
# File 'lib/melissadata/server/base.rb', line 116

def address_object
  @address_object ||= MelissaData::NativeObject::Address.new
end

#dataObject



37
38
39
# File 'lib/melissadata/server/base.rb', line 37

def data
  @data ||= {}
end

#email_objectObject



120
121
122
# File 'lib/melissadata/server/base.rb', line 120

def email_object
  @email_object ||= MelissaData::NativeObject::Email.new
end

#geo_objectObject



124
125
126
# File 'lib/melissadata/server/base.rb', line 124

def geo_object
  @geo_object ||= MelissaData::NativeObject::Geo.new
end

#inputObject



33
34
35
# File 'lib/melissadata/server/base.rb', line 33

def input
  @input ||= {}
end

#ip_objectObject



136
137
138
# File 'lib/melissadata/server/base.rb', line 136

def ip_object
  @ip_object ||= MelissaData::NativeObject::IpLocator.new
end

#name_objectObject



128
129
130
# File 'lib/melissadata/server/base.rb', line 128

def name_object
  @name_object ||= MelissaData::NativeObject::Name.new
end

#phone_objectObject



132
133
134
# File 'lib/melissadata/server/base.rb', line 132

def phone_object
  @phone_object ||= MelissaData::NativeObject::Phone.new
end

#process(opts = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/melissadata/server/base.rb', line 16

def process(opts={})
  setup(opts)
  process_address
  process_email
  process_geo
  process_name
  process_phone
  process_ip

  data
end

#process_address(address = nil, zip = nil, city = nil, state = nil) ⇒ Object Also known as: address



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/melissadata/server/base.rb', line 41

def process_address(address=nil, zip=nil, city=nil, state=nil)
  output = {}
  input[:address] = address if address.present?
  input[:zip] = zip if zip.present?
  input[:city] = city if city.present?
  input[:state] = state if state.present?

  output = address_object.process(input)
  output.delete_if{ |k,v| v.to_s.strip == "" }
  data[:address] = output
  output
end

#process_email(email = nil) ⇒ Object Also known as: email



55
56
57
58
59
60
61
62
63
# File 'lib/melissadata/server/base.rb', line 55

def process_email(email=nil)
  output = {}
  input[:email] = email.to_s if email.present?

  output = email_object.process(input)
  output.delete_if{ |k,v| v.to_s.strip == "" }
  data[:email] = output
  output
end

#process_geo(zip = nil, plus4 = nil, dpc = nil) ⇒ Object Also known as: geo



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/melissadata/server/base.rb', line 66

def process_geo(zip=nil, plus4=nil, dpc=nil)
  output = {}

  input[:zip] = zip.to_s if zip.present?
  input[:plus4] = plus4.to_s if plus4.present?
  input[:delivery_point_code] = dpc.to_s if dpc.present?

  output = geo_object.process(input)
  output.delete_if{ |k,v| v.to_s.strip == "" }
  data[:geo] = output

  output
end

#process_ip(ip = nil) ⇒ Object Also known as: ip



105
106
107
108
109
110
111
112
113
# File 'lib/melissadata/server/base.rb', line 105

def process_ip(ip=nil)
  output = {}
  input[:ip] = ip if ip.present?

  output = ip_object.process(input)
  output.delete_if{ |k,v| v.to_s.strip == "" }
  data[:ip] = output
  output
end

#process_name(first_name = nil, last_name = nil) ⇒ Object Also known as: name



81
82
83
84
85
86
87
88
89
90
# File 'lib/melissadata/server/base.rb', line 81

def process_name(first_name=nil, last_name=nil)
  output = {}
  input[:first_name] = first_name if first_name.present?
  input[:last_name] = last_name if last_name.present?

  output = name_object.process(input)
  output.delete_if{ |k,v| v.to_s.strip == "" }
  data[:name] = output
  output
end

#process_phone(phone = nil, zip = nil) ⇒ Object Also known as: phone



93
94
95
96
97
98
99
100
101
102
# File 'lib/melissadata/server/base.rb', line 93

def process_phone(phone=nil, zip=nil)
  output = {}
  input[:phone] = phone if phone.present?
  input[:zip] = zip.to_s if zip.present?

  output = phone_object.process(input)
  output.delete_if{ |k,v| v.to_s.strip == "" }
  data[:phone] = output
  output
end

#runObject



12
13
14
# File 'lib/melissadata/server/base.rb', line 12

def run
  raise 'I should have been overridden'
end

#setup(opts) ⇒ Object



28
29
30
31
# File 'lib/melissadata/server/base.rb', line 28

def setup(opts)
  @input = opts.dup
  @data = {}
end

#versionObject



140
141
142
# File 'lib/melissadata/server/base.rb', line 140

def version
  MelissaData::VERSION
end