class StripeItems
Constants
- BEFORE_BRACKET_REGEX
- INDEX_REGEX
Public Class Methods
new(fields)
click to toggle source
# File lib/embulk/input/stripe/stripe_items.rb, line 9 def initialize(fields) @fields = fields end
Public Instance Methods
get()
click to toggle source
# File lib/embulk/input/stripe/stripe_items.rb, line 13 def get result = [] items.auto_paging_each do |sub| result.push(to_row(sub)) end result end
Private Instance Methods
items()
click to toggle source
# File lib/embulk/input/stripe/stripe_items.rb, line 24 def items raise 'Please override this method and return the items.' end
to_row(sub)
click to toggle source
# File lib/embulk/input/stripe/stripe_items.rb, line 28 def to_row(sub) @fields.map do |field| # Drill down into sub items (assumes fields are delimited with '.'). sub_fields = field['name'].split('.') sub_fields.reduce(sub) do |memo, sub_field| name_match = BEFORE_BRACKET_REGEX.match(sub_field) before_bracket = name_match[1] child = memo[before_bracket] index_match = INDEX_REGEX.match(sub_field) if index_match index = index_match[1] child[index.to_i] else child end end end end