Class: Ippon::FormData::DotKey

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

Overview

A key where nested fields are represented using a dot as a separator:

root = DotKey.new("user")
root[:email].to_s # => "user.email"

address = root[:address]
address[:zip].to_s # => "user.address.zip"

Instance Method Summary collapse

Constructor Details

#initialize(value = "") ⇒ DotKey

Creates a new key.



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

def initialize(value = "")
  @value = value.to_s
end

Instance Method Details

#[](name) ⇒ Object

Creates a new subkey with a given name.



25
26
27
28
29
30
31
# File 'lib/ippon/form_data.rb', line 25

def [](name)
  if @value.empty?
    DotKey.new(name)
  else
    DotKey.new("#{@value}.#{name}")
  end
end

#to_sObject

Returns the full string representation.



20
21
22
# File 'lib/ippon/form_data.rb', line 20

def to_s
  @value
end