Class: AocCli::Tools::Reddit
- Inherits:
-
Object
- Object
- AocCli::Tools::Reddit
- Defined in:
- lib/aoc_cli/tools.rb
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#day ⇒ Object
readonly
Returns the value of attribute day.
-
#uniq ⇒ Object
readonly
Returns the value of attribute uniq.
-
#year ⇒ Object
readonly
Returns the value of attribute year.
Instance Method Summary collapse
- #cmd ⇒ Object
-
#initialize(y: Metafile.get(:year), d: Metafile.get(:day), b: Prefs.bool(key:"reddit_in_browser")) ⇒ Reddit
constructor
A new instance of Reddit.
- #link ⇒ Object
- #open ⇒ Object
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
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
93 94 95 |
# File 'lib/aoc_cli/tools.rb', line 93 def browser @browser end |
#day ⇒ Object (readonly)
Returns the value of attribute day.
93 94 95 |
# File 'lib/aoc_cli/tools.rb', line 93 def day @day end |
#uniq ⇒ Object (readonly)
Returns the value of attribute uniq.
93 94 95 |
# File 'lib/aoc_cli/tools.rb', line 93 def uniq @uniq end |
#year ⇒ Object (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
#cmd ⇒ Object
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 |
#link ⇒ Object
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 |
#open ⇒ Object
105 106 107 |
# File 'lib/aoc_cli/tools.rb', line 105 def open system("#{browser ? "open" : cmd} #{link}") end |