Class: NameChecker::Availability

Inherits:
Object
  • Object
show all
Defined in:
lib/name_checker/availability.rb

Overview

Container class to represent the availability of a word on a specific service.

Availability.new('twitter', false)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, status_input) ⇒ Availability

Returns a new instance of Availability.



12
13
14
15
# File 'lib/name_checker/availability.rb', line 12

def initialize(service, status_input)
  @service = service.to_s
  @status = parse_status(status_input)
end

Instance Attribute Details

#serviceObject (readonly)

Returns the value of attribute service.



10
11
12
# File 'lib/name_checker/availability.rb', line 10

def service
  @service
end

#statusObject

Returns the value of attribute status.



10
11
12
# File 'lib/name_checker/availability.rb', line 10

def status
  @status
end

Instance Method Details

#available?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/name_checker/availability.rb', line 21

def available?
  status == "available"
end

#to_hashObject



33
34
35
# File 'lib/name_checker/availability.rb', line 33

def to_hash
  { service: service, status: status }
end

#to_jsonObject



37
38
39
# File 'lib/name_checker/availability.rb', line 37

def to_json
  to_hash.to_json
end

#to_sObject



17
18
19
# File 'lib/name_checker/availability.rb', line 17

def to_s
  "#{service}: #{status}"
end

#unavailable?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/name_checker/availability.rb', line 25

def unavailable?
  status == "unavailable"
end

#unknown?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/name_checker/availability.rb', line 29

def unknown?
  status == "unknown"
end