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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +35 -1
  3. data/lib/wahy/cli.rb +94 -49
  4. data/lib/wahy/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5d853de63838d3a32095161363dd188cb718bd98e1e7b8ac44db9d31b768210a
4
- data.tar.gz: 921a91ff83817d791b6a393531fe8da4abd0349689ecdc307aa57016d5630be2
3
+ metadata.gz: a464603f9dc3bd456c8e2abb036f8960180022f4780b55456d08bc902d509cc2
4
+ data.tar.gz: dc613b0c8d233033c7a4c99e16d9a1834975d74fe85c9e7118bfd1f5edaf6c57
5
5
  SHA512:
6
- metadata.gz: 224f3ad775efc37663370d8669c47f1a44e925159fb12cdd46239348a3babf09557c78231b55bc34bfd6a503fc7a5b15ab475c2b2bd9c23a590056004f205603
7
- data.tar.gz: cd8cf7d256f9c7a76ff01600dea4e96750e1b10eed9da5cada6ccae8ad45d9ad7524b4a217b128575ffc6f0cd186dbbdfd45a1d66d8483b3ca5316d8328210a9
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
- Save output to a file:
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
- # Set default options
8
- options = { lang: 'eng', scripture: '1', ayah: 'all' }
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 LANGUAGE", "Language selection ('tur' or 'eng') - Default: eng") do |l|
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", "Chapter name or ID (1-114) - Default: 1") do |s|
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", "Sign/Verse number or 'all' - Default: all") do |a|
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
- opts.on("-h", "--help", "Prints this help") do
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
- # Fetch Data
35
- doc = Wahy.new_data(options[:lang])
36
- chapters = Wahy.chapters_data(doc)
37
- chapter = Wahy.scripture_data(chapters, options[:scripture])
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
- if chapter.nil?
40
- puts "Error: Scripture '#{options[:scripture]}' not found.".colorize(:red)
41
- exit 1
42
- end
49
+ run(options)
50
+ end
43
51
 
44
- # Header preparation
45
- chapter_id = chapter['ChapterID']
46
- chapter_name = chapter['ChapterName']
47
- title = "#{chapter_id}. #{chapter_name}"
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
- # Get terminal width for centering (fallback to 80 if it fails)
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
- # Print centered and colored header
54
- puts "\n"
55
- puts title.center(term_width).colorize(:green).bold
56
- puts ("=" * title.length).center(term_width).colorize(:green)
57
- puts "\n"
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
- signs = Wahy.sign_data(chapter)
68
+ # Listeleme istenmediyse normal okuma akışına devam et
69
+ chapter_node = Wahy.scripture_data(quran, options[:scripture])
60
70
 
61
- # Print verses
62
- if options[:ayah].to_s.downcase == 'all'
63
- signs.each { |sign| print_sign(sign) }
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
- sign = Wahy.take_specific_sign(signs, options[:ayah])
66
- if sign.nil?
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
- private
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
- # Helper method to print a single verse
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Wahy
4
- VERSION = "2.0.5"
4
+ VERSION = "2.0.7"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wahy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - cptangry