Class: Giter8::Pair

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

Overview

Pair represent a key-value property pair

Constant Summary collapse

PLAIN_KEY =
/^[A-Za-z_][A-Za-z0-9_]*$/.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value) ⇒ Pair

Returns a new instance of Pair.



10
11
12
13
14
15
# File 'lib/giter8/pair.rb', line 10

def initialize(key, value)
  key = key.to_sym if !key.is_a?(Symbol) && PLAIN_KEY.match?(key)

  @key = key
  @value = value
end

Instance Attribute Details

#keyObject

Returns the value of attribute key.



8
9
10
# File 'lib/giter8/pair.rb', line 8

def key
  @key
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/giter8/pair.rb', line 8

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object



23
24
25
26
27
# File 'lib/giter8/pair.rb', line 23

def ==(other)
  same_pair = other.is_a?(Pair) && other.key == @key && other.value == @value
  same_hash = other.is_a?(Hash) && other == { @key => @value }
  same_hash || same_pair
end

#truthy?Boolean

Determines whether the Pair’s value contains a truthy value. See Conditional.truthy?

Returns:

  • (Boolean)


19
20
21
# File 'lib/giter8/pair.rb', line 19

def truthy?
  Conditional.truthy? @value
end