Class: AocCli::Tools::Reddit

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(y: Metafile.get(:year), d: Metafile.get(:day), b: Prefs.bool(key:"reddit_in_browser")) ⇒ Reddit

Returns a new instance of Reddit.



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/aoc_cli/tools.rb', line 94

def initialize(y:Metafile.get(:year), 
         d:Metafile.get(:day), 
         b:Prefs.bool(key:"reddit_in_browser"))
  @year = Validate.year(y)
  @day  = Validate.day(d)
  @uniq = Database::Query
    .new(path:Paths::Database.root("reddit"))
    .select(t:"'#{year}'", where:{day:"'#{day}'"})
    .flatten[1]
  @browser = b
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



93
94
95
# File 'lib/aoc_cli/tools.rb', line 93

def browser
  @browser
end

#dayObject (readonly)

Returns the value of attribute day.



93
94
95
# File 'lib/aoc_cli/tools.rb', line 93

def day
  @day
end

#uniqObject (readonly)

Returns the value of attribute uniq.



93
94
95
# File 'lib/aoc_cli/tools.rb', line 93

def uniq
  @uniq
end

#yearObject (readonly)

Returns the value of attribute year.



93
94
95
# File 'lib/aoc_cli/tools.rb', line 93

def year
  @year
end

Instance Method Details

#cmdObject



108
109
110
111
112
# File 'lib/aoc_cli/tools.rb', line 108

def cmd
  ["ttrv", "rtv"]
    .map{|cli| cli unless `which #{cli}`.empty?}
    .reject{|cmd| cmd.nil?}&.first || "open"
end


113
114
115
116
117
# File 'lib/aoc_cli/tools.rb', line 113

def link
  "https://www.reddit.com/r/"\
  "adventofcode/comments/#{uniq}/"\
  "#{year}_day_#{day}_solutions"
end

#openObject



105
106
107
# File 'lib/aoc_cli/tools.rb', line 105

def open
  system("#{browser ? "open" : cmd} #{link}")
end