wahy 2.0.7 → 2.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a464603f9dc3bd456c8e2abb036f8960180022f4780b55456d08bc902d509cc2
4
- data.tar.gz: dc613b0c8d233033c7a4c99e16d9a1834975d74fe85c9e7118bfd1f5edaf6c57
3
+ metadata.gz: 2aca1516f21b9f51c8558274e8bfa5ffc4614ee20124139f759b61bffa7690bf
4
+ data.tar.gz: 46720531b9a2813fdd15ca874c36d3a0cf5f7e43cbe9bc7340ccae5b0f8202e9
5
5
  SHA512:
6
- metadata.gz: bcd24fc1ed36354b8a39936f2eb46e0f80b6a87d8f0ee8a2104e864880d44aba011ce6482cb53fef8cc4d600140e52146f21f765ad5958cbe18c59ba10c4ffd9
7
- data.tar.gz: 8b830196da3e6fb84894355832b156f28f760c5ffad428c722979ec8d80a07a547b636aa10d821261740e0bd0ed2c00408afa889151a887f224390a42ba39187
6
+ metadata.gz: f6aae9f1643c2cd1ef6d1b43d6ed9c5cea43b1db18d1cecb8fefdb14dd2e67e13c915ed43817153bff1548d4683eea714a70199b121126c85b820a921e901c78
7
+ data.tar.gz: a233314dcdb19df9d1765d501d6f80abac8712c8c799f62edc966d7704129abaac178ad15f7a591d1283bf3571106f97c1e64ae4d653f477c11d84caa3c32069
data/README.md CHANGED
@@ -2,17 +2,23 @@
2
2
 
3
3
  Wahy is a powerful Ruby-based tool designed to query, read, and display Quran chapters and verses directly from your terminal. It offers a clean, colorized CLI interface for quick lookup and a modular structure that allows you to use it as a library (API) in your own Ruby projects.
4
4
 
5
+ Whether you want to browse a specific chapter, search for a verse by name or number, or programmatically access Quranic text in English (Yusuf Ali) or Turkish (Elmalılı Hamdi Yazır) translations, Wahy provides a fast and intuitive way to interact with the full 114-chapter Quran.
6
+
5
7
  ## Features
6
8
 
7
9
  - **Dual Language Support:** Easily query and read verses in Turkish (`tur`) or English (`eng`).
8
10
  - **Flexible Queries:** Search chapters by their number (e.g., `2`) or their names (e.g., `"Bakara"` or `"The Cow"`).
11
+ - **Chapter Count Validation:** CLI now validates that chapter numbers are within the valid range (1–114) and shows an error for out-of-range inputs.
12
+ - **Ayah Count Warnings:** When an invalid verse number is provided, the error message now includes the total verse count and valid range for that chapter (e.g., `"This chapter has 7 ayah(s). Valid range: 1–7."`).
9
13
  - **Verse Filtering:** Retrieve an entire chapter or a specific verse (e.g., `-a 5`) with ease.
10
14
  - **Colorized Terminal UI:** Optimized reading experience with automatic text centering and highlighted verse indicators.
11
15
  - **Modular Library:** Easily integrate the data parsing logic into other Ruby applications.
16
+ - **Chapter Name Lists:** Query all chapter names as arrays via `Wahy.en_chapters` and `Wahy.tur_chapters`.
17
+ - **Ayah Count API:** Look up the number of verses in any chapter via `Wahy.ayah_count`.
12
18
 
13
19
  ## Prerequisites
14
20
 
15
- - Ruby 2.5 or higher
21
+ - Ruby 4.0.2 or higher
16
22
  - The project expects XML data files to be located in the `lib/wahy/data/` directory:
17
23
  - `config_en.xml`
18
24
  - `config_tr.xml`
@@ -53,6 +59,7 @@ You can use the wahy command directly in your terminal. By default, it displays
53
59
  | `-s` | `--scripture` | Chapter name or number (1-114) | `1` |
54
60
  | `-a` | `--ayah` | Specific verse number or 'all' | `all` |
55
61
  | - | `--list-chapters` | List all chapters in a clean table format | - |
62
+ | `-v` | `--version` | Show version | - |
56
63
  | `-h` | `--help` | Show help menu | - |
57
64
 
58
65
  Examples
@@ -87,15 +94,33 @@ wahy --list-chapters
87
94
  # List all chapters in Turkish
88
95
  wahy --list-chapters -l tur
89
96
  ```
97
+
98
+ ### CLI Validation
99
+
100
+ The CLI provides helpful error messages for invalid inputs:
101
+
102
+ **Out-of-range chapter numbers:**
103
+
104
+ ```bash
105
+ $ wahy -s 0
106
+ Error: Chapter number must be between 1 and 114. Got 0.
107
+
108
+ $ wahy -s 200
109
+ Error: Chapter number must be between 1 and 114. Got 200.
110
+ ```
111
+
112
+ **Invalid verse numbers:**
113
+
114
+ ```bash
115
+ $ wahy -s 1 -a 10
116
+ Error: Ayah #10 not found in Chapter 1 (The Opening).
117
+ This chapter has 7 ayah(s). Valid range: 1–7.
118
+ ```
119
+
90
120
  ## Listing Chapters (`--list-chapters`)
91
121
 
92
122
  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
123
 
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
124
  ### Example Output:
100
125
  ```text
101
126
  ==================================================
@@ -138,7 +163,23 @@ signs = Wahy.sign_data the_opening
138
163
 
139
164
  # 5. Get a specific sign
140
165
  sign_two = Wahy.take_specific_sign signs, 1
166
+
167
+ # 6. Get all chapter names as arrays
168
+ en_chapters = Wahy.en_chapters # → ["The Opening", "The Cow", ...]
169
+ tur_chapters = Wahy.tur_chapters # → ["Fatiha", "Bakara", ...]
170
+
171
+ # 7. Get the number of ayahs in a chapter
172
+ ayah_count = Wahy.ayah_count(1) # → 7
173
+ ayah_count = Wahy.ayah_count("Fatiha") # → 7
174
+ ayah_count = Wahy.ayah_count(999) # → 0 (unknown chapter)
141
175
  ```
142
176
  ## License
143
177
 
144
178
  This project is licensed under the MIT License.
179
+
180
+ ```text
181
+ **Gem includes two XML data**
182
+ English Quran Tranlation(/lib/data/config_en.xml): Written by Yusuf Ali
183
+ Turkish Quran Tranlation(/lib/data/config_tr.xml): Written by Elmalılı Hamdi Yazır
184
+ Special Thanks to: http://www.qurandatabase.org/Database.aspx
185
+ ```
data/lib/wahy/cli.rb CHANGED
@@ -4,12 +4,13 @@ require 'colorize'
4
4
 
5
5
  module Wahy
6
6
  class CLI
7
+
7
8
  def self.start(args)
8
9
  options = {
9
10
  lang: 'eng',
10
11
  scripture: '1',
11
12
  ayah: 'all',
12
- list_chapters: false # Yeni: Listeleme seçeneği varsayılan olarak kapalı
13
+ list_chapters: false
13
14
  }
14
15
 
15
16
  opt_parser = OptionParser.new do |opts|
@@ -27,11 +28,15 @@ module Wahy
27
28
  options[:ayah] = a
28
29
  end
29
30
 
30
- # Yeni: Sadece sureleri listelemek için argüman
31
31
  opts.on("--list-chapters", "List all chapters in a table format for the selected language") do
32
32
  options[:list_chapters] = true
33
33
  end
34
34
 
35
+ opts.on("-v", "--version", "Prints the current version") do
36
+ puts "wahy version #{Wahy::VERSION}"
37
+ exit
38
+ end
39
+
35
40
  opts.on("-h", "--help", "Prints this help menu") do
36
41
  puts opts
37
42
  exit
@@ -59,14 +64,24 @@ module Wahy
59
64
 
60
65
  quran = Wahy.chapters_data(data)
61
66
 
62
- # Eğer list-chapters bayrağı tetiklendiyse, tabloyu çiz ve programı sonlandır
63
67
  if options[:list_chapters]
64
68
  display_chapter_list(quran, options[:lang])
65
69
  exit
66
70
  end
67
71
 
68
- # Listeleme istenmediyse normal okuma akışına devam et
69
- chapter_node = Wahy.scripture_data(quran, options[:scripture])
72
+ scripture_input = options[:scripture].to_s
73
+
74
+ # Check chapter number range for numeric input
75
+ if scripture_input =~ /^\d+$/
76
+ chapter_num = scripture_input.to_i
77
+ if chapter_num < 1 || chapter_num > 114
78
+ puts "Error: Chapter number must be between 1 and 114. Got #{chapter_num}.".red
79
+ exit 1
80
+ end
81
+ end
82
+
83
+ scripture_id = options[:scripture]
84
+ chapter_node = Wahy.scripture_data(quran, scripture_id)
70
85
 
71
86
  unless chapter_node
72
87
  puts "Error: Scripture '#{options[:scripture]}' could not be found.".red
@@ -76,17 +91,19 @@ module Wahy
76
91
  chapter_id = chapter_node['ChapterID']
77
92
  chapter_name = chapter_node['ChapterName']
78
93
  verses = chapter_node.xpath('Verse')
94
+ total_verses = verses.length
79
95
 
80
96
  selected_verses = []
81
97
  if options[:ayah].to_s.downcase == 'all'
82
98
  selected_verses = verses
83
99
  else
84
- target_ayah = options[:ayah].to_s
85
- match = verses.find { |v| v['VerseID'] == target_ayah }
100
+ target_ayah = options[:ayah].to_i
101
+ match = verses.find { |v| v['VerseID'] == target_ayah.to_s }
86
102
  if match
87
103
  selected_verses = [match]
88
104
  else
89
105
  puts "Error: Ayah ##{target_ayah} not found in Chapter #{chapter_id} (#{chapter_name}).".red
106
+ puts "This chapter has #{total_verses} ayah(s). Valid range: 1-#{total_verses}.".red
90
107
  exit 1
91
108
  end
92
109
  end
@@ -109,7 +126,6 @@ module Wahy
109
126
  puts "=" * terminal_width
110
127
  end
111
128
 
112
- # Yeni: Sureleri tablo halinde terminale basan yardımcı metod
113
129
  def self.display_chapter_list(chapters, lang)
114
130
  lang_display = lang.to_s.downcase.start_with?('t') ? "TURKISH" : "ENGLISH"
115
131
 
@@ -117,14 +133,12 @@ module Wahy
117
133
  puts " QURAN CHAPTERS (#{lang_display}) ".center(50).cyan.bold
118
134
  puts "=" * 50
119
135
 
120
- # Sütun başlıkları: Sola dayalı 10 karakter ID, sola dayalı 35 karakter İsim
121
136
  puts sprintf("%-10s | %-35s", "ID", "CHAPTER NAME").yellow.bold
122
137
  puts "-" * 50
123
138
 
124
139
  chapters.each do |c|
125
140
  id = c['ChapterID']
126
141
  name = c['ChapterName']
127
- # Sütun verilerini hizalayarak yazdır
128
142
  puts sprintf("%-10s | %-35s", id, name)
129
143
  end
130
144
 
data/lib/wahy/parser.rb CHANGED
@@ -52,5 +52,40 @@ module Wahy
52
52
  def take_specific_sign(signs, verse_number)
53
53
  signs.find { |verse| verse["VerseID"] == verse_number.to_s }
54
54
  end
55
+
56
+ # Returns an array of chapter names from a parsed document
57
+ # @param doc [Nokogiri::XML::Document]
58
+ def chapter_names(doc)
59
+ doc.xpath("//Chapter").map { |c| c["ChapterName"] }
60
+ end
61
+
62
+ # Returns the number of ayahs (verses) in a chapter
63
+ # @param identifier [String, Integer] Chapter ID or name
64
+ # @return [Integer]
65
+ def ayah_count(identifier)
66
+ doc = new_data("eng")
67
+ chapters = doc.xpath("//Chapter")
68
+ chapter = if identifier.to_s =~ /^\d+$/
69
+ chapters.find { |c| c["ChapterID"] == identifier.to_s }
70
+ else
71
+ chapters.find { |c| c["ChapterName"].downcase == identifier.downcase }
72
+ end
73
+ return 0 unless chapter
74
+ chapter.xpath("Verse").count
75
+ end
76
+
77
+ # Returns an array of English chapter names
78
+ # @return [Array<String>]
79
+ def en_chapters
80
+ doc = new_data("eng")
81
+ chapter_names(doc)
82
+ end
83
+
84
+ # Returns an array of Turkish chapter names
85
+ # @return [Array<String>]
86
+ def tur_chapters
87
+ doc = new_data("tur")
88
+ chapter_names(doc)
89
+ end
55
90
  end
56
91
  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.7"
4
+ VERSION = "2.0.9"
5
5
  end
data/sig/wahy.rbs CHANGED
@@ -1,4 +1,15 @@
1
1
  module Wahy
2
2
  VERSION: String
3
+
3
4
  # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+
6
+ new_data(lang: String) Nokogiri::XML::Document
7
+ chapters_data(doc: Nokogiri::XML::Document) Nokogiri::XML::NodeSet
8
+ scripture_data(chapters: Nokogiri::XML::NodeSet, identifier: String) Nokogiri::XML::Node?
9
+ sign_data(chapter: Nokogiri::XML::Node) Array[Nokogiri::XML::Node]
10
+ take_specific_sign(signs: Array[Nokogiri::XML::Node], verse_number: String) Nokogiri::XML::Node?
11
+ chapter_names(doc: Nokogiri::XML::Document) Array[String]
12
+ en_chapters() Array[String]
13
+ tur_chapters() Array[String]
14
+ ayah_count(identifier: String) Integer
4
15
  end
data/wahy.gemspec CHANGED
@@ -8,8 +8,14 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ["cptangry"]
9
9
  spec.email = ["caglar.gokhan@gmail.com"]
10
10
 
11
- spec.summary = "A CLI tool and library to query the Holy Quran in TR/ENG."
12
- spec.description = "Query and read the Holy Quran chapters and verses in the terminal with colored output. Includes both English and Turkish support."
11
+ spec.summary = "Query the Quran in your terminal with colorized output and a Ruby library API."
12
+ spec.description = <<~DESC
13
+ Wahy is a CLI tool and Ruby library for querying the Holy Quran's 114 chapters
14
+ and verses. Browse chapters by name or number, filter specific ayahs, and
15
+ display results with colorized terminal output. Supports English (Yusuf Ali)
16
+ and Turkish (Elmalılı Hamdi Yazır) translations. Also usable as a library to
17
+ programmatically access chapter names, verse counts, and parsed Quranic data.
18
+ DESC
13
19
  spec.homepage = "https://github.com/cptangry/wahy"
14
20
  spec.license = "MIT"
15
21
  spec.required_ruby_version = ">= 4.0.2"
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.7
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - cptangry
@@ -79,8 +79,12 @@ dependencies:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: 0.8.1
82
- description: Query and read the Holy Quran chapters and verses in the terminal with
83
- colored output. Includes both English and Turkish support.
82
+ description: |
83
+ Wahy is a CLI tool and Ruby library for querying the Holy Quran's 114 chapters
84
+ and verses. Browse chapters by name or number, filter specific ayahs, and
85
+ display results with colorized terminal output. Supports English (Yusuf Ali)
86
+ and Turkish (Elmalılı Hamdi Yazır) translations. Also usable as a library to
87
+ programmatically access chapter names, verse counts, and parsed Quranic data.
84
88
  email:
85
89
  - caglar.gokhan@gmail.com
86
90
  executables:
@@ -124,5 +128,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
128
  requirements: []
125
129
  rubygems_version: 4.0.6
126
130
  specification_version: 4
127
- summary: A CLI tool and library to query the Holy Quran in TR/ENG.
131
+ summary: Query the Quran in your terminal with colorized output and a Ruby library
132
+ API.
128
133
  test_files: []