Class: AocCli::Tools::Convert

Inherits:
Request
  • Object
show all
Defined in:
lib/aoc_cli/tools.rb

Direct Known Subclasses

Get, Post

Instance Attribute Summary collapse

Attributes inherited from Request

#base, #day, #page, #ua, #user, #year

Instance Method Summary collapse

Methods inherited from Request

#initialize

Constructor Details

This class inherits a constructor from AocCli::Tools::Request

Instance Attribute Details

#inputObject

Returns the value of attribute input.



45
46
47
# File 'lib/aoc_cli/tools.rb', line 45

def input
  @input
end

Instance Method Details

#arrayObject



46
47
48
# File 'lib/aoc_cli/tools.rb', line 46

def array
  input.split("\n")
end

#chunk(f:, t:, t_off: 0, f_off: 0) ⇒ Object



49
50
51
52
53
54
# File 'lib/aoc_cli/tools.rb', line 49

def chunk(f:, t:, t_off:0, f_off:0)
  pt1 = array.index {|l| l =~ /#{f}/} + t_off
  pt2 = array.rindex{|l| l =~ /#{t}/} + f_off
  @input = array.slice(pt1, pt2 - pt1).join("\n")
  self
end

#mdObject



61
62
63
64
# File 'lib/aoc_cli/tools.rb', line 61

def md
  PandocRuby.new(input, {f: html, t: :gfm}, 
     md_head, md_ref).convert
end

#plainObject



58
59
60
# File 'lib/aoc_cli/tools.rb', line 58

def plain
  PandocRuby.new(input, f: html, t: :plain).convert
end

#rawObject



55
56
57
# File 'lib/aoc_cli/tools.rb', line 55

def raw
  input.split("\n").join("\n")
end