wahy 2.0.8 → 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 +4 -4
- data/README.md +47 -1
- data/lib/wahy/cli.rb +18 -12
- data/lib/wahy/parser.rb +35 -0
- data/lib/wahy/version.rb +1 -1
- data/sig/wahy.rbs +11 -0
- data/wahy.gemspec +8 -2
- metadata +9 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2aca1516f21b9f51c8558274e8bfa5ffc4614ee20124139f759b61bffa7690bf
|
|
4
|
+
data.tar.gz: 46720531b9a2813fdd15ca874c36d3a0cf5f7e43cbe9bc7340ccae5b0f8202e9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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,6 +94,29 @@ 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.
|
|
@@ -133,7 +163,23 @@ signs = Wahy.sign_data the_opening
|
|
|
133
163
|
|
|
134
164
|
# 5. Get a specific sign
|
|
135
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)
|
|
136
175
|
```
|
|
137
176
|
## License
|
|
138
177
|
|
|
139
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
|
@@ -5,13 +5,12 @@ require 'colorize'
|
|
|
5
5
|
module Wahy
|
|
6
6
|
class CLI
|
|
7
7
|
|
|
8
|
-
|
|
9
8
|
def self.start(args)
|
|
10
9
|
options = {
|
|
11
10
|
lang: 'eng',
|
|
12
11
|
scripture: '1',
|
|
13
12
|
ayah: 'all',
|
|
14
|
-
list_chapters: false
|
|
13
|
+
list_chapters: false
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
opt_parser = OptionParser.new do |opts|
|
|
@@ -29,12 +28,10 @@ module Wahy
|
|
|
29
28
|
options[:ayah] = a
|
|
30
29
|
end
|
|
31
30
|
|
|
32
|
-
# Yeni: Sadece sureleri listelemek için argüman
|
|
33
31
|
opts.on("--list-chapters", "List all chapters in a table format for the selected language") do
|
|
34
32
|
options[:list_chapters] = true
|
|
35
33
|
end
|
|
36
34
|
|
|
37
|
-
# Yeni: Versiyon numarasını gösterir
|
|
38
35
|
opts.on("-v", "--version", "Prints the current version") do
|
|
39
36
|
puts "wahy version #{Wahy::VERSION}"
|
|
40
37
|
exit
|
|
@@ -67,14 +64,24 @@ module Wahy
|
|
|
67
64
|
|
|
68
65
|
quran = Wahy.chapters_data(data)
|
|
69
66
|
|
|
70
|
-
# Eğer list-chapters bayrağı tetiklendiyse, tabloyu çiz ve programı sonlandır
|
|
71
67
|
if options[:list_chapters]
|
|
72
68
|
display_chapter_list(quran, options[:lang])
|
|
73
69
|
exit
|
|
74
70
|
end
|
|
75
71
|
|
|
76
|
-
|
|
77
|
-
|
|
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)
|
|
78
85
|
|
|
79
86
|
unless chapter_node
|
|
80
87
|
puts "Error: Scripture '#{options[:scripture]}' could not be found.".red
|
|
@@ -84,17 +91,19 @@ module Wahy
|
|
|
84
91
|
chapter_id = chapter_node['ChapterID']
|
|
85
92
|
chapter_name = chapter_node['ChapterName']
|
|
86
93
|
verses = chapter_node.xpath('Verse')
|
|
94
|
+
total_verses = verses.length
|
|
87
95
|
|
|
88
96
|
selected_verses = []
|
|
89
97
|
if options[:ayah].to_s.downcase == 'all'
|
|
90
98
|
selected_verses = verses
|
|
91
99
|
else
|
|
92
|
-
target_ayah = options[:ayah].
|
|
93
|
-
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 }
|
|
94
102
|
if match
|
|
95
103
|
selected_verses = [match]
|
|
96
104
|
else
|
|
97
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
|
|
98
107
|
exit 1
|
|
99
108
|
end
|
|
100
109
|
end
|
|
@@ -117,7 +126,6 @@ module Wahy
|
|
|
117
126
|
puts "=" * terminal_width
|
|
118
127
|
end
|
|
119
128
|
|
|
120
|
-
# Yeni: Sureleri tablo halinde terminale basan yardımcı metod
|
|
121
129
|
def self.display_chapter_list(chapters, lang)
|
|
122
130
|
lang_display = lang.to_s.downcase.start_with?('t') ? "TURKISH" : "ENGLISH"
|
|
123
131
|
|
|
@@ -125,14 +133,12 @@ module Wahy
|
|
|
125
133
|
puts " QURAN CHAPTERS (#{lang_display}) ".center(50).cyan.bold
|
|
126
134
|
puts "=" * 50
|
|
127
135
|
|
|
128
|
-
# Sütun başlıkları: Sola dayalı 10 karakter ID, sola dayalı 35 karakter İsim
|
|
129
136
|
puts sprintf("%-10s | %-35s", "ID", "CHAPTER NAME").yellow.bold
|
|
130
137
|
puts "-" * 50
|
|
131
138
|
|
|
132
139
|
chapters.each do |c|
|
|
133
140
|
id = c['ChapterID']
|
|
134
141
|
name = c['ChapterName']
|
|
135
|
-
# Sütun verilerini hizalayarak yazdır
|
|
136
142
|
puts sprintf("%-10s | %-35s", id, name)
|
|
137
143
|
end
|
|
138
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
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 = "
|
|
12
|
-
spec.description =
|
|
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.
|
|
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:
|
|
83
|
-
|
|
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:
|
|
131
|
+
summary: Query the Quran in your terminal with colorized output and a Ruby library
|
|
132
|
+
API.
|
|
128
133
|
test_files: []
|