Skip to content

Commit

Permalink
Adhere to the plugin file layout suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
svoop committed Dec 14, 2023
1 parent 6e0e29d commit fb64379
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 140 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Main

Nothing so far
#### Changes
* Adhere to plugin file layout suggestions

## 0.4.3

Expand Down
22 changes: 0 additions & 22 deletions lib/rodbot/plugins/word_of_the_day/adapter.rb

This file was deleted.

27 changes: 0 additions & 27 deletions lib/rodbot/plugins/word_of_the_day/adapters/base.rb

This file was deleted.

34 changes: 0 additions & 34 deletions lib/rodbot/plugins/word_of_the_day/adapters/merriam_webster.rb

This file was deleted.

54 changes: 0 additions & 54 deletions lib/rodbot/plugins/word_of_the_day/adapters/transparent.rb

This file was deleted.

18 changes: 18 additions & 0 deletions lib/rodbot/plugins/word_of_the_day/lib/adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

require_relative 'adapters/base'
require_relative 'adapters/merriam_webster'
require_relative 'adapters/transparent'

module WordOfTheDay
class Adapter
extend Forwardable

def_delegator :@adapter, :message, :message

def initialize(language)
@language = language
@adapter = (language == 'English' ? MerriamWebster : Transparent).new(language)
end
end
end
23 changes: 23 additions & 0 deletions lib/rodbot/plugins/word_of_the_day/lib/adapters/base.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'httpx'

module WordOfTheDay
class Adapter
class Base
attr_reader :language

def initialize(language)
@language = language.downcase
end

def message
if word
"[#{word}](#{url}) (#{language.capitalize})"
else
"~~#{language.capitalize}~~"
end
end
end
end
end
30 changes: 30 additions & 0 deletions lib/rodbot/plugins/word_of_the_day/lib/adapters/merriam_webster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

module WordOfTheDay
class Adapter
class MerriamWebster < Base
private

def word
html.match(/<h2 class="word-header-txt">(.+?)</)&.captures&.first
end

def url
"https://www.merriam-webster.com/word-of-the-day/#{today}"
end

private

def today
Time.now.strftime('%F')
end

def html
case (response = HTTPX.get(url))
in { status: 200 } then response.body.to_s
else ''
end
end
end
end
end
50 changes: 50 additions & 0 deletions lib/rodbot/plugins/word_of_the_day/lib/adapters/transparent.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# frozen_string_literal: true

module WordOfTheDay
class Adapter
class Transparent < Base
LANGUAGE_CODES = {
'arabic' => 'ar',
'chinese' => 'zh',
'dutch' => 'nl',
'esperanto' => 'esp',
'french' => 'fr',
'german' => 'de',
'irish' => 'ga',
'italian' => 'it',
'japanese' => 'ja',
'latin' => 'la',
'polish' => 'pl',
'portuguese' => 'pt',
'russian' => 'ru',
'spanish' => 'es'
}.freeze

def word
xml.match(/<word>(.+?)</)&.captures&.first
end

def url
"https://wotd.transparent.com/widget/?lang=#{language}&date=#{today}"
end

private

def today
Time.now.strftime('%m-%d-%Y')
end

def language_code
LANGUAGE_CODES.fetch(language, language)
end

def xml
xml_url = "https://wotd.transparent.com/rss/#{today}-#{language_code}-widget.xml"
case (response = HTTPX.get(xml_url))
in { status: 200 } then response.body.to_s
else ''
end
end
end
end
end
4 changes: 2 additions & 2 deletions lib/rodbot/plugins/word_of_the_day/schedule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require 'httpx'

require_relative 'adapter'
require_relative 'lib/adapter'

module Rodbot
class Plugins
Expand All @@ -23,7 +23,7 @@ def languages
end

def message
languages.map { Adapter.new(_1).message }.compact.join(' / ')
languages.map { ::WordOfTheDay::Adapter.new(_1).message }.compact.join(' / ')
end
end
end
Expand Down

0 comments on commit fb64379

Please sign in to comment.