Class: Ippon::FormData::BracketKey

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

Overview

A key where nested fields are represented using bracket notation:

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

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

Instance Method Summary collapse

Constructor Details

#initialize(value = "") ⇒ BracketKey

Creates a new key.



43
44
45
# File 'lib/ippon/form_data.rb', line 43

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

Instance Method Details

#[](name) ⇒ Object

Creates a new subkey with a given name.



53
54
55
56
57
58
59
# File 'lib/ippon/form_data.rb', line 53

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

#to_sObject

Returns the full string representation.



48
49
50
# File 'lib/ippon/form_data.rb', line 48

def to_s
  @value
end