wq 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/exe/wq ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wq"
5
+
6
+ Wq::CLI.start
@@ -0,0 +1,40 @@
1
+ module CommandKit
2
+ module Colors
3
+ module ANSI
4
+ # ANSI code for italics text
5
+ ITALICS = "\e[3m"
6
+
7
+ # ANSI code to disable italics
8
+ RESET_ITALICS = "\e[23m"
9
+
10
+ module_function
11
+
12
+ #
13
+ # Italicizes the text.
14
+ #
15
+ # @param [String, nil] string
16
+ # An optional string.
17
+ #
18
+ # @return [String, ITALICS]
19
+ # The italicized string or just {ITALICS} if no arguments were given.
20
+ #
21
+ # @see ITALICS
22
+ #
23
+ # @api public
24
+ #
25
+ def italics(string=nil)
26
+ if string then "#{ITALICS}#{string}#{RESET_ITALICS}"
27
+ else ITALICS
28
+ end
29
+ end
30
+ end
31
+
32
+ module PlainText
33
+ module_function
34
+
35
+ def italics(string=nil)
36
+ string || ""
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ module Wq
2
+ class CLI
3
+ module Commands
4
+ class Inspire < CommandKit::Command
5
+ include CommandKit::Printing::Indent
6
+ include CommandKit::Colors
7
+
8
+ command_name 'inspire'
9
+ description 'Show random inspirational quote.'
10
+
11
+ def run
12
+ puts ""
13
+ indent(2) do
14
+ puts colors.white("\"#{quote[:text]}\"")
15
+ puts colors.gray("-- #{quote[:author]}")
16
+ end
17
+ puts ""
18
+ end
19
+
20
+ def quote
21
+ @quote ||= Wq::Data.quotes.sample
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ module Wq
2
+ class CLI
3
+ module Commands
4
+ class List < CommandKit::Command
5
+ include CommandKit::Printing::Indent
6
+ include CommandKit::Colors
7
+
8
+ command_name 'list'
9
+ description 'Show all or filtered words.'
10
+
11
+ argument :letter, required: false, usage: 'A', desc: "The starting letter to filter words by."
12
+
13
+ def run(letter=nil)
14
+ if letter.nil?
15
+ words = Wq::Data.words
16
+ else
17
+ words = Wq::Data.words.select { |w| w[:word].start_with?(letter.downcase) }
18
+ end
19
+
20
+ if words.empty?
21
+ print_error("No words found starting with '#{letter.downcase}'.")
22
+ exit 1
23
+ else
24
+ words.each do |word|
25
+ puts "#{word[:word]} - #{word[:meanings].first[:definition]}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ module Wq
2
+ class CLI
3
+ module Commands
4
+ class Random < CommandKit::Command
5
+ include CommandKit::Printing::Indent
6
+ include CommandKit::Colors
7
+
8
+ command_name 'random'
9
+ description 'Show random word.'
10
+
11
+ def run
12
+ puts ""
13
+ puts colors.yellow(colors.bold(word[:word]))
14
+ puts ""
15
+
16
+ grouped_meanings.each do |part_of_speech, meanings|
17
+ puts part_of_speech
18
+ puts ""
19
+ indent(2) do
20
+ meanings.each do |meaning|
21
+ puts colors.white(meaning[:definition])
22
+ puts ['"', meaning[:example], '"'].join
23
+
24
+ synonyms = meaning[:synonyms].compact.join(", ")
25
+ puts ["\u{21BB}", synonyms].join(" ") if !meaning[:synonyms].empty?
26
+
27
+ puts ""
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def word
34
+ @word ||= Wq::Data.words.sample
35
+ end
36
+
37
+ def grouped_meanings
38
+ word[:meanings].group_by { |w| w[:partOfSpeech] }
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,54 @@
1
+ module Wq
2
+ class CLI
3
+ module Commands
4
+ class Today < CommandKit::Command
5
+ include CommandKit::Printing::Indent
6
+ include CommandKit::Colors
7
+
8
+ command_name 'today'
9
+ description 'Show the word and quote of the day.'
10
+
11
+ def run
12
+ puts "📚 Word of the Day"
13
+ puts ""
14
+ puts colors.yellow(colors.bold(word[:word]))
15
+ puts ""
16
+ grouped_meanings.each do |part_of_speech, meanings|
17
+ puts part_of_speech
18
+ puts ""
19
+ indent(2) do
20
+ meanings.each do |meaning|
21
+ puts colors.white(meaning[:definition])
22
+ puts colors.gray(['"', meaning[:example], '"'].join)
23
+ puts ""
24
+ end
25
+ end
26
+ end
27
+ puts ""
28
+ puts "💬 Quote of the Day"
29
+ puts ""
30
+ indent(2) do
31
+ puts "\"#{quote[:text]}\""
32
+ puts colors.gray("-— #{quote[:author]}")
33
+ end
34
+ end
35
+
36
+ def random_today
37
+ @random_today ||= ::Random.new(Date.today.to_s.delete("-").to_i)
38
+ end
39
+
40
+ def word
41
+ @word ||= Wq::Data.words.sample(random: random_today)
42
+ end
43
+
44
+ def grouped_meanings
45
+ word[:meanings].group_by { |w| w[:partOfSpeech] }
46
+ end
47
+
48
+ def quote
49
+ @quote ||= Wq::Data.quotes.sample(random: random_today)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/wq/cli.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "command_kit"
2
+ require "command_kit/bug_report"
3
+ require "command_kit/commands"
4
+ require "command_kit/commands/auto_load"
5
+ require "command_kit/colors"
6
+ require "command_kit/printing/indent"
7
+ require "command_kit/options/version"
8
+ require_relative "cli/colors_ext"
9
+
10
+ module Wq
11
+ class CLI
12
+ include CommandKit::Commands
13
+ include CommandKit::Commands::AutoLoad.new(
14
+ dir: "#{__dir__}/cli/commands",
15
+ namespace: "#{self}::Commands",
16
+ )
17
+ include CommandKit::Options::Version
18
+ include CommandKit::BugReport
19
+
20
+ command_name "wq"
21
+ version Wq::VERSION
22
+
23
+ command_aliases['quote'] = 'inspire'
24
+
25
+ bug_report_url "https://github.com/javierjulio/wq/issues/new"
26
+ end
27
+ end
data/lib/wq/data.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wq
4
+ module Data
5
+ PATH = File.expand_path("../../../data", __FILE__)
6
+
7
+ def self.words
8
+ JSON.parse(File.read(words_path), symbolize_names: true)
9
+ end
10
+
11
+ def self.words_path
12
+ File.join(PATH, "words.json")
13
+ end
14
+
15
+ def self.quotes
16
+ JSON.parse(File.read(quotes_path), symbolize_names: true)
17
+ end
18
+
19
+ def self.quotes_path
20
+ File.join(PATH, "quotes.json")
21
+ end
22
+ end
23
+ end
data/lib/wq/version.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Wq
4
+ VERSION = "1.0.0"
5
+ end
data/lib/wq.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+ require "json"
5
+ require_relative "wq/version"
6
+ require_relative "wq/data"
7
+ require_relative "wq/cli"
8
+
9
+ module Wq
10
+ class Error < StandardError; end
11
+ # Your code goes here...
12
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wq
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Javier Julio
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: command_kit
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.6'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.6'
26
+ description: A command-line tool (wq) to help you learn 500+ words you should know
27
+ but probably don't and find inspirational quotes.
28
+ email:
29
+ - jjfutbol@gmail.com
30
+ executables:
31
+ - wq
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE.txt
36
+ - README.md
37
+ - data/quotes.json
38
+ - data/words.json
39
+ - exe/wq
40
+ - lib/wq.rb
41
+ - lib/wq/cli.rb
42
+ - lib/wq/cli/colors_ext.rb
43
+ - lib/wq/cli/commands/inspire.rb
44
+ - lib/wq/cli/commands/list.rb
45
+ - lib/wq/cli/commands/random.rb
46
+ - lib/wq/cli/commands/today.rb
47
+ - lib/wq/data.rb
48
+ - lib/wq/version.rb
49
+ homepage: https://github.com/javierjulio/wq
50
+ licenses:
51
+ - MIT
52
+ metadata:
53
+ homepage_uri: https://github.com/javierjulio/wq
54
+ source_code_uri: https://github.com/javierjulio/wq.git
55
+ bug_tracker_uri: https://github.com/javierjulio/wq/issues
56
+ rubygems_mfa_required: 'true'
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.2.0
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubygems_version: 3.7.2
72
+ specification_version: 4
73
+ summary: A CLI (wq) to learn 500+ words and inspirational quotes.
74
+ test_files: []