Skip to content

Commit

Permalink
Dependency updates and cleanup, lints fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
nomoon committed Oct 3, 2018
1 parent e3e4c72 commit 517bec7
Show file tree
Hide file tree
Showing 19 changed files with 230 additions and 164 deletions.
38 changes: 13 additions & 25 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
AllCops:
TargetRubyVersion: 2.2
TargetRubyVersion: 2.3

# Layout
Layout/EmptyLineAfterGuardClause:
Enabled: false

# Metrics
Metrics/AbcSize:
Description: >-
A calculated magnitude based on number of assignments,
branches, and conditions.
Reference: 'http://c2.com/cgi/wiki?AbcMetric'
Enabled: false
Max: 20
Enabled: true

Metrics/BlockNesting:
Description: 'Avoid excessive block nesting'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#three-is-the-number-thou-shalt-count'
Enabled: true
Max: 4

Expand All @@ -21,42 +18,30 @@ Metrics/BlockLength:
- spec/**/*.rb

Metrics/ClassLength:
Description: 'Avoid classes longer than 250 lines of code.'
Enabled: true
Max: 250

Metrics/CyclomaticComplexity:
Description: >-
A complexity metric that is strongly correlated to the number
of test cases needed to validate a method.
Enabled: true
Max: 10

Metrics/LineLength:
Description: 'Limit lines to 80 characters.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#80-character-limits'
Enabled: false
Enabled: true
Max: 120

Metrics/MethodLength:
Description: 'Avoid methods longer than 40 lines of code.'
Enabled: true
Max: 40

Metrics/ModuleLength:
Description: 'Avoid modules longer than 250 lines of code.'
Enabled: true
Max: 250

Metrics/ParameterLists:
Description: 'Avoid parameter lists longer than three or four parameters.'
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#too-many-params'
Enabled: true

Metrics/PerceivedComplexity:
Description: >-
A complexity metric geared towards measuring complexity for a
human reader.
Enabled: false
Enabled: true

# Style
Style/AsciiComments:
Expand Down Expand Up @@ -93,7 +78,10 @@ Style/StringLiterals:
Style/SymbolArray:
Enabled: true

Style/TrailingCommaInLiteral:
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: comma

Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: comma

Style/TrivialAccessors:
Expand Down
11 changes: 3 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
sudo: false
language: ruby
rvm:
- 2.4.2
- 2.3.5
- 2.2.8
- ruby-head
- 2.5.1
- 2.4.4
- 2.3.7
env:
- RUST=yes
- RUST=no

matrix:
allow_failures:
- rvm: ruby-head

before_install:
- if [[ "$RUST" == "yes" ]]; then curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain stable; export PATH="$HOME/.cargo/bin:$PATH"; fi

Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "rusty_sanscript"
version = "0.4.1"
version = "0.5.0"
authors = ["Tim Bellefleur <nomoon@phoebus.ca>"]
publish = false

[dependencies]
lazy_static = "^0.2.10"
ruby-sys = "^0.3.0"
regex = "^0.2.2"
lazy_static = "^1.1"
ruby-sys = "^0.3"
regex = "^1.0"

[lib]
crate-type = ["cdylib"]
3 changes: 2 additions & 1 deletion lib/sanscript.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "ragabash"
require "active_support/core_ext/object/deep_dup"
require "ice_nine"

require "sanscript/version"
require "sanscript/rust"
Expand Down
24 changes: 19 additions & 5 deletions lib/sanscript/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,27 @@ def self.ips(*)
module Benchmark
TEST_STRINGS = {
brahmic: {
devanagari: "नानाशास्त्रसुभाषितामृतरसैः श्रोत्रोत्सवं कुर्वतां येषां यान्ति दिनानि पण्डितजनव्यायामखिन्नात्मनाम् तेषां जन्म च जीवितं च सुकृतं तैर् एव भूर् भूषिता शेषैह् किं पशुवद् विवेकरहितैर् भूभारभूतैर् नरः",
malayalam: "നാനാശാസ്ത്രസുഭാഷിതാമൃതരസൈഃ ശ്രോത്രോത്സവം കുര്വതാം യേഷാം യാന്തി ദിനാനി പണ്ഡിതജനവ്യായാമഖിന്നാത്മനാമ് തേഷാം ജന്മ ച ജീവിതം ച സുകൃതം തൈര് ഏവ ഭൂര് ഭൂഷിതാ ശേഷൈഹ് കിം പശുവദ് വിവേകരഹിതൈര് ഭൂഭാരഭൂതൈര് നരഃ",
devanagari: "नानाशास्त्रसुभाषितामृतरसैः श्रोत्रोत्सवं कुर्वतां येषां यान्ति दिनानि " \
"पण्डितजनव्यायामखिन्नात्मनाम् तेषां जन्म च जीवितं च सुकृतं तैर् एव भूर् " \
"भूषिता शेषैह् किं पशुवद् विवेकरहितैर् भूभारभूतैर् नरः",
malayalam: "നാനാശാസ്ത്രസുഭാഷിതാമൃതരസൈഃ ശ്രോത്രോത്സവം കുര്വതാം " \
"യേഷാം യാന്തി ദിനാനി പണ്ഡിതജനവ്യായാമഖിന്നാത്മനാമ് " \
"തേഷാം ജന്മ ച ജീവിതം ച സുകൃതം തൈര് ഏവ ഭൂര് ഭൂഷിതാ " \
"ശേഷൈഹ് കിം പശുവദ് വിവേകരഹിതൈര് ഭൂഭാരഭൂതൈര് നരഃ",
}.freeze,
roman: {
iast: "nānāśāstrasubhāṣitāmṛtarasaiḥ śrotrotsavaṃ kurvatāṃ yeṣāṃ yānti dināni paṇḍitajanavyāyāmakhinnātmanām teṣāṃ janma ca jīvitaṃ ca sukṛtaṃ tair eva bhūr bhūṣitā śeṣaih kiṃ paśuvad vivekarahitair bhūbhārabhūtair naraḥ",
slp1: "nAnASAstrasuBAzitAmftarasEH SrotrotsavaM kurvatAM yezAM yAnti dinAni paRqitajanavyAyAmaKinnAtmanAm tezAM janma ca jIvitaM ca sukftaM tEr eva BUr BUzitA SezEh kiM paSuvad vivekarahitEr BUBAraBUtEr naraH",
hk: "nAnAzAstrasubhASitAmRtarasaiH zrotrotsavaM kurvatAM yeSAM yAnti dinAni paNDitajanavyAyAmakhinnAtmanAm teSAM janma ca jIvitaM ca sukRtaM tair eva bhUr bhUSitA zeSaih kiM pazuvad vivekarahitair bhUbhArabhUtair naraH",
iast: "nānāśāstrasubhāṣitāmṛtarasaiḥ śrotrotsavaṃ kurvatāṃ yeṣāṃ " \
"yānti dināni paṇḍitajanavyāyāmakhinnātmanām teṣāṃ janma ca " \
"jīvitaṃ ca sukṛtaṃ tair eva bhūr bhūṣitā śeṣaih kiṃ paśuvad " \
"vivekarahitair bhūbhārabhūtair naraḥ",
slp1: "nAnASAstrasuBAzitAmftarasEH SrotrotsavaM kurvatAM yezAM yAnti " \
"dinAni paRqitajanavyAyAmaKinnAtmanAm tezAM janma ca jIvitaM " \
"ca sukftaM tEr eva BUr BUzitA SezEh kiM paSuvad vivekarahitEr " \
"BUBAraBUtEr naraH",
hk: "nAnAzAstrasubhASitAmRtarasaiH zrotrotsavaM kurvatAM yeSAM yAnti " \
"dinAni paNDitajanavyAyAmakhinnAtmanAm teSAM janma ca jIvitaM ca " \
"sukRtaM tair eva bhUr bhUSitA zeSaih kiM pazuvad vivekarahitair " \
"bhUbhArabhUtair naraH",
}.freeze,
}.freeze

Expand Down
5 changes: 4 additions & 1 deletion lib/sanscript/detect/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ module Detect
BRAHMIC_SCRIPTS_ORDER = %i[devanagari bengali gurmukhi gujarati oriya tamil telugu kannada malayalam].freeze

# Match on special Roman characters
RE_IAST_OR_KOLKATA_ONLY = /[āīūṛṝḷḹēōṃḥṅñṭḍṇśṣḻĀĪŪṚṜḶḸĒŌṂḤṄÑṬḌṆŚṢḺ]|[aiueoAIUEO]\u0304|[rlRL]\u0323\u0304?|[mhtdMHTD]\u0323|[nN][\u0307\u0303\u0323]|[sS][\u0301\u0323]|[lL]\u0331/
RE_IAST_OR_KOLKATA_ONLY = /[āīūṛṝḷḹēōṃḥṅñṭḍṇśṣḻĀĪŪṚṜḶḸĒŌṂḤṄÑṬḌṆŚṢḺ]|
[aiueoAIUEO]\u0304|[rlRL]\u0323\u0304?|
[mhtdMHTD]\u0323|[nN][\u0307\u0303\u0323]|
[sS][\u0301\u0323]|[lL]\u0331/x

# Match on Kolkata-specific Roman characters
RE_KOLKATA_ONLY = /[ēōĒŌ]|[eoEO]\u0304/
Expand Down
2 changes: 1 addition & 1 deletion lib/sanscript/detect/ruby24.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Ruby24
#
# @param text [String] a string of Sanskrit text
# @return [Symbol, nil] the Symbol of the scheme, or nil if no match
def ruby_detect_scheme(text)
def ruby_detect_scheme(text) # rubocop:disable AbcSize, PerceivedComplexity
text = text.to_str.gsub(RE_CONTROL_BLOCK, "")

# Brahmic schemes are all within a specific range of code points.
Expand Down
7 changes: 4 additions & 3 deletions lib/sanscript/detect/ruby2x.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ module Ruby2x
#
# @param text [String] a string of Sanskrit text
# @return [Symbol, nil] the Symbol of the scheme, or nil if no match
def ruby_detect_scheme(text)
def ruby_detect_scheme(text) # rubocop:disable AbcSize, PerceivedComplexity
text = text.to_str.gsub(RE_CONTROL_BLOCK, "")

# rubocop:disable Style/CaseEquality

# Brahmic schemes are all within a specific range of code points.
brahmic_char = text[RE_BRAHMIC_RANGE]
return BRAHMIC_SCRIPTS_ORDER[(brahmic_char.ord - 0x0900) / 0x80] if brahmic_char

# rubocop:disable Style/CaseEquality

# Romanizations
if RE_IAST_OR_KOLKATA_ONLY === text
return :kolkata if RE_KOLKATA_ONLY === text
Expand All @@ -33,6 +33,7 @@ def ruby_detect_scheme(text)
elsif RE_HARVARD_KYOTO === text
:hk
end
# rubocop:enable Style/CaseEquality
end
end
end
Expand Down
20 changes: 11 additions & 9 deletions lib/sanscript/transliterate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require "sanscript/transliterate/schemes"
module Sanscript
using ::Ragabash::Refinements
# Sanskrit transliteration module.
# Derived from Sanscript (https://github.com/sanskrit/sanscript.js), which is
# released under the MIT and GPL Licenses.
Expand Down Expand Up @@ -39,6 +38,8 @@ class << self

module_function

# rubocop:disable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity

# Check whether the given scheme encodes Brahmic Sanskrit.
#
# @param name [Symbol] the scheme name
Expand Down Expand Up @@ -73,7 +74,7 @@ def roman_scheme?(name)
def add_brahmic_scheme(name, scheme)
name = name.to_sym
scheme = scheme.deep_dup
@schemes[name] = scheme.deep_freeze
@schemes[name] = IceNine.deep_freeze(scheme)
@brahmic_schemes.add(name)
@scheme_names.add(name)
scheme
Expand All @@ -89,7 +90,7 @@ def add_roman_scheme(name, scheme)
name = name.to_sym
scheme = scheme.deep_dup
scheme[:vowel_marks] = scheme[:vowels][1..-1] unless scheme.key?(:vowel_marks)
@schemes[name] = scheme.deep_freeze
@schemes[name] = IceNine.deep_freeze(scheme)
@roman_schemes.add(name)
@scheme_names.add(name)
scheme
Expand Down Expand Up @@ -128,7 +129,7 @@ def add_roman_scheme(name, scheme)
add_roman_scheme(:itrans_dravidian, itrans_dravidian)

# ensure deep freeze on alternates
@all_alternates.each_value { |alternates| alternates.deep_freeze } # rubocop:disable Style/SymbolProc
@all_alternates.each_value { |alternates| IceNine.deep_freeze(alternates) }
end

# Transliterate from one script to another.
Expand Down Expand Up @@ -210,15 +211,15 @@ def make_map(from, to)
end
end

{
IceNine.deep_freeze(
consonants: consonants,
from_roman?: roman_scheme?(from),
letters: letters,
marks: marks,
max_token_length: token_lengths.max,
to_roman?: roman_scheme?(to),
virama: to_scheme[:virama].first,
}.deep_freeze
virama: to_scheme[:virama].first
)
end
end

Expand All @@ -227,7 +228,7 @@ def make_map(from, to)
# @param data [String] the string to transliterate
# @param map [Hash] map data generated from {#make_map}
# @return [String] the transliterated string
def transliterate_roman(data, map, options = {}) # rubocop:disable MethodLength, CyclomaticComplexity
def transliterate_roman(data, map, options = {})
data = data.to_str.chars
buf = []
token_buffer = []
Expand Down Expand Up @@ -302,7 +303,7 @@ def transliterate_roman(data, map, options = {}) # rubocop:disable MethodLength,
# @param data [String] the string to transliterate
# @param map [Hash] map data generated from {#make_map}
# @return [String] the transliterated string
def transliterate_brahmic(data, map) # rubocop:disable MethodLength, CyclomaticComplexity
def transliterate_brahmic(data, map)
data = data.to_str.chars
buf = []
had_roman_consonant = false
Expand Down Expand Up @@ -369,5 +370,6 @@ def transliterate_brahmic(data, map) # rubocop:disable MethodLength, CyclomaticC
buf.join("")
end
end
# rubocop:enable AbcSize, CyclomaticComplexity, MethodLength, PerceivedComplexity
end
end

0 comments on commit 517bec7

Please sign in to comment.