Class: Recruitee::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/recruitee/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, properties) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
# File 'lib/recruitee/resource.rb', line 7

def initialize(client, properties)
  @client = client
  @properties = deep_symbolize_keys(properties)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/recruitee/resource.rb', line 20

def method_missing(name, *args)
  if name.to_s.end_with?('=')
    attr = name.to_s[0...-1].to_sym
    @properties[attr] = args.first
  elsif @properties.key?(name)
    @properties[name]
  else
    super
  end
end

Instance Attribute Details

#propertiesObject (readonly)

Returns the value of attribute properties.



5
6
7
# File 'lib/recruitee/resource.rb', line 5

def properties
  @properties
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/recruitee/resource.rb', line 12

def [](key)
  @properties[key.to_sym]
end

#[]=(key, value) ⇒ Object



16
17
18
# File 'lib/recruitee/resource.rb', line 16

def []=(key, value)
  send(:"#{key}=", value)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/recruitee/resource.rb', line 31

def respond_to_missing?(name, include_private = false)
  attr = name.to_s.end_with?('=') ? name.to_s[0...-1].to_sym : name
  @properties.key?(attr) || super
end

#to_sObject



36
37
38
39
# File 'lib/recruitee/resource.rb', line 36

def to_s
  values = @properties.map { |k, v| "#{k}: #{v}" }.join(' ')
  "<#{self.class.name} #{values}>"
end