class DataFormatter::Collection
Attributes
indentation[R]
items[R]
lang[R]
separator[R]
Public Class Methods
new(args)
click to toggle source
# File lib/data_formatter/collection.rb, line 6 def initialize(args) @indentation = args.fetch(:indentation) @separator = args.fetch(:separator, ",") @lang = args.fetch(:lang, "ruby") @items = prepare(args.fetch(:data)) end
Public Instance Methods
to_s()
click to toggle source
# File lib/data_formatter/collection.rb, line 13 def to_s return inline if items.length < 2 [].tap do |output| output << open indentation.increase items.each_with_index do |item, i| output << indent(item) + separator(i) end indentation.decrease output << indent(close) end.map do |x| x.to_s.force_encoding("UTF-8") end.join("\n") end
Protected Instance Methods
close()
click to toggle source
# File lib/data_formatter/collection.rb, line 40 def close nil end
indent(item)
click to toggle source
# File lib/data_formatter/collection.rb, line 52 def indent(item) indentation.indent(item) end
inline()
click to toggle source
# File lib/data_formatter/collection.rb, line 44 def inline [open, items[0].to_s, close].compact.join end
open()
click to toggle source
# File lib/data_formatter/collection.rb, line 36 def open nil end
prepare(items)
click to toggle source
# File lib/data_formatter/collection.rb, line 32 def prepare(items) items end