wahy 2.0.5 → 2.0.6
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/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: 665ed20de1fda09d4a4e86b984f0da8b7f17447383ab0e8d57624b8326912513
|
|
4
|
+
data.tar.gz: d3cb429e690f296c81a746c4616eed472947f872d6f0def1ca05eaf9f04b7994
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a732cc0e89bd2a228d62a778740e1afdacec092ebf84d9da74ddb226a093408d48118b61ee33487a683c1a351d1eeea5140fb044775483ed10cbf80d6bbd4264
|
|
7
|
+
data.tar.gz: e683adf860b008fcfda72740adf5a227303bbdc272f75c17840df171be63d4d188a79e697fef969104540c754a766489125a652cf2f5b5fe6b6b81b8709501f6
|
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