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)


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

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



29
30
31
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 29

def game
  raise_abstract_method __method__
end

#image_local_pathPathname

Returns:

  • (Pathname)


34
35
36
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 34

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)


40
41
42
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 40

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)


47
48
49
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 47

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”



52
53
54
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 52

def sections
  raise_abstract_method __method__
end

#title_iconString

Returns:

  • (String)


57
58
59
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 57

def title_icon
  raise_abstract_method __method__
end

#title_to_s(title) ⇒ Object



65
66
67
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 65

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

#to_sObject



61
62
63
# File 'lib/ehbrs_ruby_utils/bga/whatsapp_formatter.rb', line 61

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