Module: EhbrsRubyUtils::Bga::WhatsappFormatter

Included in:
GameStatistics::WhatsappFormatter, Table::WhatsappFormatters::Base
Defined in:
lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb,
lib/ehbrs_ruby_utils/bga/whatsapp_formatter/option.rb

Defined Under Namespace

Classes: Option

Constant Summary collapse

LINE_SEPARATOR =
"\n"
OPTION_SEPARATOR =
LINE_SEPARATOR
SECTION_SEPARATOR =
"#{LINE_SEPARATOR}#{LINE_SEPARATOR}"

Instance Method Summary collapse

Instance Method Details

#content_to_s(content) ⇒ String

Parameters:

  • content (String, Enumerable)

Returns:

  • (String)


18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 18

def content_to_s(content)
  if content.is_a?(::Hash)
    content_to_s(
      content.map { |k, v| ::EhbrsRubyUtils::Bga::WhatsappFormatter::Option.new(k, v) }
    )
  elsif content.is_a?(::Enumerable)
    content.to_a.join(OPTION_SEPARATOR)
  else
    content.to_s
  end
end

#gameEhbrsRubyUtils::Bga::Game



31
32
33
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 31

def game
  raise_abstract_method __method__
end

#image_local_pathPathname

Returns:

  • (Pathname)


36
37
38
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 36

def image_local_path
  game.box_large_image.local_path
end

#options_to_s(options) ⇒ String

Parameters:

  • options (Enumerable<EhbrsRubyUtils::Bga::WhatsappFormatters::Option>)

Returns:

  • (String)


42
43
44
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 42

def options_to_s(options)
  options.map { |o| "#{o}#{OPTION_SEPARATOR}" }
end

#section_to_s(title, content) ⇒ String

Parameters:

  • title (String)
  • content (String)

Returns:

  • (String)


49
50
51
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 49

def section_to_s(title, content)
  [title_to_s(title), content_to_s(content)].map(&:strip).join(SECTION_SEPARATOR)
end

#sectionsHash<String, String>

Returns “title” => “content”.

Returns:

  • (Hash<String, String>)

    “title” => “content”



54
55
56
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 54

def sections
  raise_abstract_method __method__
end

#title_iconString

Returns:

  • (String)


59
60
61
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 59

def title_icon
  raise_abstract_method __method__
end

#title_to_s(title) ⇒ Object



67
68
69
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 67

def title_to_s(title)
  "*#{[title_icon, title, title_icon].join(' ')}*"
end

#to_sObject



63
64
65
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 63

def to_s
  sections.map { |title, content| section_to_s(title, content) }.join(SECTION_SEPARATOR)
end