Class: NestedSend::Checker

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

Class Method Summary collapse

Class Method Details

.is_complete_string?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/nested_send.rb', line 28

def self.is_complete_string?(attribute)
  start_char = attribute[0]
  end_char = attribute[-1]
  does_match = (start_char == end_char)
  return does_match if is_string_hash?(attribute)
  return false
end

.is_string_hash?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
# File 'lib/nested_send.rb', line 19

def self.is_string_hash?(attribute)
  strings = ["'", '"']
  strings.include?(attribute[0]) && strings.include?(attribute[-1])
end

.is_stringified_array?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/nested_send.rb', line 24

def self.is_stringified_array?(attribute)
  return attribute.to_i.to_s == attribute
end

.is_symbolized_hash?(attribute) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/nested_send.rb', line 15

def self.is_symbolized_hash?(attribute)
  return attribute[0] == ':'
end

.kind_of_attribute(kind) ⇒ Object



10
11
12
13
# File 'lib/nested_send.rb', line 10

def self.kind_of_attribute(kind)
  return :method if kind == '.'
  return :collection if kind == '['
end

.kind_of_collection(attribute) ⇒ Object



3
4
5
6
7
8
# File 'lib/nested_send.rb', line 3

def self.kind_of_collection(attribute)
  return :sym_hash if is_symbolized_hash?(attribute)
  return :str_hash if is_complete_string?(attribute)
  return :array if is_stringified_array?(attribute)
  return false
end