wahy 2.0.5 → 2.0.7
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.
- checksums.yaml +4 -4
- data/README.md +35 -1
- data/lib/wahy/cli.rb +94 -49
- data/lib/wahy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a464603f9dc3bd456c8e2abb036f8960180022f4780b55456d08bc902d509cc2
|
|
4
|
+
data.tar.gz: dc613b0c8d233033c7a4c99e16d9a1834975d74fe85c9e7118bfd1f5edaf6c57
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bcd24fc1ed36354b8a39936f2eb46e0f80b6a87d8f0ee8a2104e864880d44aba011ce6482cb53fef8cc4d600140e52146f21f765ad5958cbe18c59ba10c4ffd9
|
|
7
|
+
data.tar.gz: 8b830196da3e6fb84894355832b156f28f760c5ffad428c722979ec8d80a07a547b636aa10d821261740e0bd0ed2c00408afa889151a887f224390a42ba39187
|
data/README.md
CHANGED
|
@@ -52,6 +52,7 @@ You can use the wahy command directly in your terminal. By default, it displays
|
|
|
52
52
|
| `-l` | `--lang` | Language selection (`tur` or `eng`) | `eng` |
|
|
53
53
|
| `-s` | `--scripture` | Chapter name or number (1-114) | `1` |
|
|
54
54
|
| `-a` | `--ayah` | Specific verse number or 'all' | `all` |
|
|
55
|
+
| - | `--list-chapters` | List all chapters in a clean table format | - |
|
|
55
56
|
| `-h` | `--help` | Show help menu | - |
|
|
56
57
|
|
|
57
58
|
Examples
|
|
@@ -77,7 +78,40 @@ wahy -l tur -s <chapter_number> -a <verse_number>
|
|
|
77
78
|
wahy -s <chapter_mame_or_number> -a <verse_number>
|
|
78
79
|
```
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
List all chapters in Turkish:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# List all chapters in English (default)
|
|
85
|
+
wahy --list-chapters
|
|
86
|
+
|
|
87
|
+
# List all chapters in Turkish
|
|
88
|
+
wahy --list-chapters -l tur
|
|
89
|
+
```
|
|
90
|
+
## Listing Chapters (`--list-chapters`)
|
|
91
|
+
|
|
92
|
+
The `--list-chapters` feature acts as an interactive built-in index for the Quranic data files. It provides users with a clean, well-aligned terminal table showing the exact `ID` and `Chapter Name` mappings for the selected language.
|
|
93
|
+
|
|
94
|
+
### Key Benefits:
|
|
95
|
+
1. **Dynamic Language Switch:** Specifying `-l 'tur'` or `-l 'eng'` alongside `--list-chapters` automatically switches the content of the index table to that specific translation file.
|
|
96
|
+
2. **Short-Circuit Execution:** When this flag is triggered, the program instantly renders the table and exits securely, avoiding any unnecessary XML traversing or verse filtering overhead.
|
|
97
|
+
3. **Formatted UI Output:** Utilizing explicit string formatting rules ensures that all tabular column lines down the terminal remain perfectly aligned regardless of varying chapter name lengths.
|
|
98
|
+
|
|
99
|
+
### Example Output:
|
|
100
|
+
```text
|
|
101
|
+
==================================================
|
|
102
|
+
QURAN CHAPTERS (TURKISH)
|
|
103
|
+
==================================================
|
|
104
|
+
ID | CHAPTER NAME
|
|
105
|
+
--------------------------------------------------
|
|
106
|
+
1 | Fatiha
|
|
107
|
+
2 | Bakara
|
|
108
|
+
3 | Âl-i İmrân
|
|
109
|
+
...
|
|
110
|
+
114 | Nas
|
|
111
|
+
==================================================
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Save output to a file:
|
|
81
115
|
|
|
82
116
|
```bash
|
|
83
117
|
wahy -s <chapter_name_or_number> -a <verse_number> > output.txt
|
data/lib/wahy/cli.rb
CHANGED
|
@@ -1,89 +1,134 @@
|
|
|
1
|
+
# lib/wahy/cli.rb
|
|
1
2
|
require 'optparse'
|
|
2
3
|
require 'colorize'
|
|
3
4
|
|
|
4
5
|
module Wahy
|
|
5
6
|
class CLI
|
|
6
7
|
def self.start(args)
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
options = {
|
|
9
|
+
lang: 'eng',
|
|
10
|
+
scripture: '1',
|
|
11
|
+
ayah: 'all',
|
|
12
|
+
list_chapters: false # Yeni: Listeleme seçeneği varsayılan olarak kapalı
|
|
13
|
+
}
|
|
9
14
|
|
|
10
15
|
opt_parser = OptionParser.new do |opts|
|
|
11
16
|
opts.banner = "Usage: wahy [options]"
|
|
12
17
|
|
|
13
|
-
opts.on("-l", "--lang
|
|
18
|
+
opts.on("-l", "--lang LANG", "Pick language ('eng'|'tur' or 'en'|'tr') [Default: eng]") do |l|
|
|
14
19
|
options[:lang] = l
|
|
15
20
|
end
|
|
16
21
|
|
|
17
|
-
opts.on("-s", "--scripture SCRIPTURE", "
|
|
22
|
+
opts.on("-s", "--scripture SCRIPTURE", "Pick scripture name or number (1-114) [Default: 1]") do |s|
|
|
18
23
|
options[:scripture] = s
|
|
19
24
|
end
|
|
20
25
|
|
|
21
|
-
opts.on("-a", "--ayah AYAH", "
|
|
26
|
+
opts.on("-a", "--ayah AYAH", "Pick sign/ayah number or 'all' [Default: all]") do |a|
|
|
22
27
|
options[:ayah] = a
|
|
23
28
|
end
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
# Yeni: Sadece sureleri listelemek için argüman
|
|
31
|
+
opts.on("--list-chapters", "List all chapters in a table format for the selected language") do
|
|
32
|
+
options[:list_chapters] = true
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
opts.on("-h", "--help", "Prints this help menu") do
|
|
26
36
|
puts opts
|
|
27
37
|
exit
|
|
28
38
|
end
|
|
29
39
|
end
|
|
30
40
|
|
|
31
|
-
opt_parser.parse!(args)
|
|
32
|
-
|
|
33
41
|
begin
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
opt_parser.parse!(args)
|
|
43
|
+
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
|
44
|
+
puts "CLI Error: #{e.message}".red
|
|
45
|
+
puts opt_parser
|
|
46
|
+
exit 1
|
|
47
|
+
end
|
|
38
48
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
exit 1
|
|
42
|
-
end
|
|
49
|
+
run(options)
|
|
50
|
+
end
|
|
43
51
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
52
|
+
def self.run(options)
|
|
53
|
+
begin
|
|
54
|
+
data = Wahy.new_data(options[:lang])
|
|
55
|
+
rescue => e
|
|
56
|
+
puts "Error: #{e.message}".red
|
|
57
|
+
exit 1
|
|
58
|
+
end
|
|
48
59
|
|
|
49
|
-
|
|
50
|
-
term_width = `tput cols`.to_i rescue 80
|
|
51
|
-
term_width = 80 if term_width == 0
|
|
60
|
+
quran = Wahy.chapters_data(data)
|
|
52
61
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
62
|
+
# Eğer list-chapters bayrağı tetiklendiyse, tabloyu çiz ve programı sonlandır
|
|
63
|
+
if options[:list_chapters]
|
|
64
|
+
display_chapter_list(quran, options[:lang])
|
|
65
|
+
exit
|
|
66
|
+
end
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
# Listeleme istenmediyse normal okuma akışına devam et
|
|
69
|
+
chapter_node = Wahy.scripture_data(quran, options[:scripture])
|
|
60
70
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
unless chapter_node
|
|
72
|
+
puts "Error: Scripture '#{options[:scripture]}' could not be found.".red
|
|
73
|
+
exit 1
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
chapter_id = chapter_node['ChapterID']
|
|
77
|
+
chapter_name = chapter_node['ChapterName']
|
|
78
|
+
verses = chapter_node.xpath('Verse')
|
|
79
|
+
|
|
80
|
+
selected_verses = []
|
|
81
|
+
if options[:ayah].to_s.downcase == 'all'
|
|
82
|
+
selected_verses = verses
|
|
83
|
+
else
|
|
84
|
+
target_ayah = options[:ayah].to_s
|
|
85
|
+
match = verses.find { |v| v['VerseID'] == target_ayah }
|
|
86
|
+
if match
|
|
87
|
+
selected_verses = [match]
|
|
64
88
|
else
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
puts "Error: Ayah '#{options[:ayah]}' not found in this scripture.".colorize(:red)
|
|
68
|
-
else
|
|
69
|
-
print_sign(sign)
|
|
70
|
-
end
|
|
89
|
+
puts "Error: Ayah ##{target_ayah} not found in Chapter #{chapter_id} (#{chapter_name}).".red
|
|
90
|
+
exit 1
|
|
71
91
|
end
|
|
72
|
-
puts "\n"
|
|
73
|
-
rescue => e
|
|
74
|
-
puts "An error occurred: #{e.message}".colorize(:red)
|
|
75
|
-
exit 1
|
|
76
92
|
end
|
|
93
|
+
|
|
94
|
+
terminal_width = 75
|
|
95
|
+
puts "=" * terminal_width
|
|
96
|
+
header_title = "Chapter #{chapter_id}: #{chapter_name}"
|
|
97
|
+
puts header_title.center(terminal_width).upcase.cyan.bold
|
|
98
|
+
puts "=" * terminal_width
|
|
99
|
+
puts ""
|
|
100
|
+
|
|
101
|
+
selected_verses.each do |v|
|
|
102
|
+
verse_id = v['VerseID']
|
|
103
|
+
verse_text = v.text.strip
|
|
104
|
+
|
|
105
|
+
print "[#{verse_id}] ".green.bold
|
|
106
|
+
puts verse_text.white
|
|
107
|
+
puts ""
|
|
108
|
+
end
|
|
109
|
+
puts "=" * terminal_width
|
|
77
110
|
end
|
|
78
111
|
|
|
79
|
-
|
|
112
|
+
# Yeni: Sureleri tablo halinde terminale basan yardımcı metod
|
|
113
|
+
def self.display_chapter_list(chapters, lang)
|
|
114
|
+
lang_display = lang.to_s.downcase.start_with?('t') ? "TURKISH" : "ENGLISH"
|
|
115
|
+
|
|
116
|
+
puts "=" * 50
|
|
117
|
+
puts " QURAN CHAPTERS (#{lang_display}) ".center(50).cyan.bold
|
|
118
|
+
puts "=" * 50
|
|
119
|
+
|
|
120
|
+
# Sütun başlıkları: Sola dayalı 10 karakter ID, sola dayalı 35 karakter İsim
|
|
121
|
+
puts sprintf("%-10s | %-35s", "ID", "CHAPTER NAME").yellow.bold
|
|
122
|
+
puts "-" * 50
|
|
123
|
+
|
|
124
|
+
chapters.each do |c|
|
|
125
|
+
id = c['ChapterID']
|
|
126
|
+
name = c['ChapterName']
|
|
127
|
+
# Sütun verilerini hizalayarak yazdır
|
|
128
|
+
puts sprintf("%-10s | %-35s", id, name)
|
|
129
|
+
end
|
|
80
130
|
|
|
81
|
-
|
|
82
|
-
def self.print_sign(sign)
|
|
83
|
-
verse_id = sign['VerseID']
|
|
84
|
-
# CDATA text parsing and whitespace stripping
|
|
85
|
-
text = sign.text.strip
|
|
86
|
-
puts "[#{verse_id}] ".colorize(:cyan).bold + text
|
|
131
|
+
puts "=" * 50
|
|
87
132
|
end
|
|
88
133
|
end
|
|
89
134
|
end
|
data/lib/wahy/version.rb
CHANGED