Class: WebPay::Mock::Builder
- Inherits:
-
Object
- Object
- WebPay::Mock::Builder
- Includes:
- Util
- Defined in:
- lib/webpay/mock/builder.rb
Constant Summary collapse
- PREFIX =
{ charge: 'ch', customer: 'cus', token: 'tok', event: 'evt', account: 'acct' }.freeze
- ID_LETTERS =
('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
Instance Attribute Summary collapse
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
- #build ⇒ Object
-
#initialize(object) ⇒ Builder
constructor
A new instance of Builder.
- #set_from(hash, *allowed_keys) ⇒ Object
Methods included from Util
Constructor Details
#initialize(object) ⇒ Builder
Returns a new instance of Builder.
14 15 16 17 18 19 20 21 22 |
# File 'lib/webpay/mock/builder.rb', line 14 def initialize(object) @hash = {} @hash['object'] = object.to_s return if @hash['object'] == 'card' @hash['id'] = PREFIX[object.to_sym] + '_' + 15.times.map { ID_LETTERS[rand(ID_LETTERS.length)] }.join return if @hash['object'] == 'account' @hash['livemode'] = false @hash['created'] = Time.now.to_i end |
Instance Attribute Details
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
12 13 14 |
# File 'lib/webpay/mock/builder.rb', line 12 def hash @hash end |
Instance Method Details
#[]=(key, value) ⇒ Object
24 25 26 |
# File 'lib/webpay/mock/builder.rb', line 24 def []=(key, value) @hash[key.to_s] = value end |
#build ⇒ Object
36 37 38 |
# File 'lib/webpay/mock/builder.rb', line 36 def build stringify_keys(@hash) end |
#set_from(hash, *allowed_keys) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/webpay/mock/builder.rb', line 28 def set_from(hash, *allowed_keys) allowed_string_keys = allowed_keys.map(&:to_s) hash.each do |k, v| @hash[k.to_s] = v if allowed_string_keys.empty? || allowed_string_keys.include?(k.to_s) end self end |