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', recursion: 'rec', 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.
15 16 17 18 19 20 21 22 23 |
# File 'lib/webpay/mock/builder.rb', line 15 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.
13 14 15 |
# File 'lib/webpay/mock/builder.rb', line 13 def hash @hash end |
Instance Method Details
#[]=(key, value) ⇒ Object
25 26 27 |
# File 'lib/webpay/mock/builder.rb', line 25 def []=(key, value) @hash[key.to_s] = value end |
#build ⇒ Object
37 38 39 |
# File 'lib/webpay/mock/builder.rb', line 37 def build stringify_keys(@hash) end |
#set_from(hash, *allowed_keys) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/webpay/mock/builder.rb', line 29 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 |