rika 1.6.0-java → 2.0.0-java

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 (84) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +6 -4
  3. data/.rubocop.yml +49 -0
  4. data/Gemfile +12 -0
  5. data/README.md +226 -47
  6. data/RELEASE_NOTES.md +43 -0
  7. data/Rakefile +4 -7
  8. data/bin/rika +13 -0
  9. data/lib/rika/cli/args_parser.rb +131 -0
  10. data/lib/rika/cli/rika_command.rb +129 -0
  11. data/lib/rika/formatters.rb +39 -0
  12. data/lib/rika/parse_result.rb +34 -0
  13. data/lib/rika/parser.rb +84 -0
  14. data/lib/rika/tika_loader.rb +65 -0
  15. data/lib/rika/version.rb +3 -1
  16. data/lib/rika.rb +96 -104
  17. data/pom.xml +2 -2
  18. data/rika.gemspec +30 -15
  19. data/rika_helper.rb +30 -0
  20. data/spec/fixtures/de.txt +21 -1
  21. data/spec/fixtures/document.doc +0 -0
  22. data/spec/fixtures/document.docx +0 -0
  23. data/spec/fixtures/document.pdf +0 -0
  24. data/spec/fixtures/document.txt +23 -0
  25. data/spec/fixtures/en.txt +23 -1
  26. data/spec/fixtures/es.txt +21 -1
  27. data/spec/fixtures/fr.txt +23 -1
  28. data/spec/fixtures/image_jpg_without_extension +0 -0
  29. data/spec/fixtures/ru.txt +21 -1
  30. data/spec/fixtures/tiny.txt +1 -0
  31. data/spec/rika/cli/args_parser_spec.rb +117 -0
  32. data/spec/rika/cli/rika_command_spec.rb +120 -0
  33. data/spec/rika/formatters_spec.rb +23 -0
  34. data/spec/rika/parse_result_spec.rb +42 -0
  35. data/spec/rika/parser_spec.rb +304 -0
  36. data/spec/rika/rika_spec.rb +10 -0
  37. data/spec/rika/tika_loader_spec.rb +57 -0
  38. data/spec/spec_helper.rb +13 -5
  39. metadata +54 -98
  40. data/.travis.yml +0 -7
  41. data/spec/fixtures/over_100k_file.txt +0 -1241
  42. data/spec/fixtures/text_file.txt +0 -1
  43. data/spec/fixtures/text_file_without_extension +0 -1
  44. data/spec/rika_spec.rb +0 -202
  45. data/target/dependency/apache-mime4j-core-0.7.2.jar +0 -0
  46. data/target/dependency/apache-mime4j-dom-0.7.2.jar +0 -0
  47. data/target/dependency/asm-debug-all-4.1.jar +0 -0
  48. data/target/dependency/aspectjrt-1.8.0.jar +0 -0
  49. data/target/dependency/bcmail-jdk15-1.45.jar +0 -0
  50. data/target/dependency/bcprov-jdk15-1.45.jar +0 -0
  51. data/target/dependency/boilerpipe-1.1.0.jar +0 -0
  52. data/target/dependency/commons-codec-1.9.jar +0 -0
  53. data/target/dependency/commons-compress-1.8.1.jar +0 -0
  54. data/target/dependency/commons-httpclient-3.1.jar +0 -0
  55. data/target/dependency/commons-logging-1.1.1.jar +0 -0
  56. data/target/dependency/fontbox-1.8.6.jar +0 -0
  57. data/target/dependency/isoparser-1.0.2.jar +0 -0
  58. data/target/dependency/java-libpst-0.8.1.jar +0 -0
  59. data/target/dependency/jcip-annotations-1.0.jar +0 -0
  60. data/target/dependency/jdom-1.0.jar +0 -0
  61. data/target/dependency/jempbox-1.8.6.jar +0 -0
  62. data/target/dependency/jhighlight-1.0.jar +0 -0
  63. data/target/dependency/jmatio-1.0.jar +0 -0
  64. data/target/dependency/juniversalchardet-1.0.3.jar +0 -0
  65. data/target/dependency/metadata-extractor-2.6.2.jar +0 -0
  66. data/target/dependency/netcdf-4.2.20.jar +0 -0
  67. data/target/dependency/pdfbox-1.8.6.jar +0 -0
  68. data/target/dependency/poi-3.11-beta2.jar +0 -0
  69. data/target/dependency/poi-ooxml-3.11-beta2.jar +0 -0
  70. data/target/dependency/poi-ooxml-schemas-3.11-beta2.jar +0 -0
  71. data/target/dependency/poi-scratchpad-3.11-beta2.jar +0 -0
  72. data/target/dependency/rome-1.0.jar +0 -0
  73. data/target/dependency/slf4j-api-1.6.1.jar +0 -0
  74. data/target/dependency/tagsoup-1.2.1.jar +0 -0
  75. data/target/dependency/tika-core-1.6.jar +0 -0
  76. data/target/dependency/tika-parsers-1.6.jar +0 -0
  77. data/target/dependency/unidataCommon-4.2.20.jar +0 -0
  78. data/target/dependency/vorbis-java-core-0.6.jar +0 -0
  79. data/target/dependency/vorbis-java-tika-0.6.jar +0 -0
  80. data/target/dependency/xercesImpl-2.8.1.jar +0 -0
  81. data/target/dependency/xml-apis-1.3.03.jar +0 -0
  82. data/target/dependency/xmlbeans-2.6.0.jar +0 -0
  83. data/target/dependency/xmpcore-5.1.2.jar +0 -0
  84. data/target/dependency/xz-1.5.jar +0 -0
data/spec/fixtures/de.txt CHANGED
@@ -1 +1,21 @@
1
- Er hörte leise Schritte hinter sich. Das bedeutete nichts Gutes. Wer würde ihm schon folgen, spät in der Nacht und dazu noch in dieser engen Gasse mitten im übel beleumundeten Hafenviertel? Gerade jetzt, wo er das Ding seines Lebens gedreht hatte und mit der Beute verschwinden wollte! Hatte einer seiner zahllosen Kollegen dieselbe Idee gehabt, ihn beobachtet und abgewartet, um ihn nun um die Früchte seiner Arbeit zu erleichtern? Oder gehörten die Schritte hinter ihm zu einem der unzähligen Gesetzeshüter dieser Stadt, und die stählerne Acht um seine Handgelenke würde gleich zuschnappen? Er konnte die Aufforderung stehen zu bleiben schon hören. Gehetzt sah er sich um. Plötzlich erblickte er den schmalen Durchgang. Blitzartig drehte er sich nach rechts und verschwand zwischen den beiden Gebäuden. Beinahe wäre er dabei über den umgestürzten Mülleimer gefallen, der mitten im Weg lag. Er versuchte, sich in der Dunkelheit seinen Weg zu ertasten und erstarrte: Anscheinend gab es keinen anderen Ausweg aus diesem kleinen Hof als den Durchgang, durch den er gekommen war. Die Schritte wurden lauter und lauter, er sah eine dunkle Gestalt um die Ecke biegen. Fieberhaft irrten seine Augen durch die nächtliche Dunkelheit und suchten einen Ausweg. War jetzt wirklich alles vorbei,
1
+ Eines verschneiten Abends im Wald verhaltend (German)
2
+
3
+ Wohl weiß ich, wer den Wald besitzt,
4
+ Sein Haus jedoch im Dorf dort ist;
5
+ Er merkt nicht, wie ich hier verharr'
6
+ Zu schaun, wie Wald den Schnee begrüßt.
7
+
8
+ Mein Pferdchen denkt, ich wär ein Narr,
9
+ Zu halten, wo nicht Haus noch Farm,
10
+ Im Wald, nah beim gefrornen Teich,
11
+ Am finstersten Abend im Jahr.
12
+
13
+ Des Zaumzeugs Glöckchen klingen leis:
14
+ Es fragt: was ist? geht's weiter gleich?
15
+ Ansonsten hört man nur ganz sacht
16
+ Den Schneefall und den Wind, der streicht.
17
+
18
+ Der Wald ist nett, tief wie die Nacht,
19
+ Doch halte ich, was ich versprach,
20
+ Und Meilen sind's noch bis zum Schlaf,
21
+ Und Meilen sind's noch bis zum Schlaf.
Binary file
Binary file
Binary file
@@ -0,0 +1,23 @@
1
+ Stopping by Woods on a Snowy Evening
2
+
3
+ By Robert Frost
4
+
5
+ Whose woods these are I think I know.
6
+ His house is in the village though;
7
+ He will not see me stopping here
8
+ To watch his woods fill up with snow.
9
+
10
+ My little horse must think it queer
11
+ To stop without a farmhouse near
12
+ Between the woods and frozen lake
13
+ The darkest evening of the year.
14
+
15
+ He gives his harness bells a shake
16
+ To ask if there is some mistake.
17
+ The only other sound’s the sweep
18
+ Of easy wind and downy flake.
19
+
20
+ The woods are lovely, dark and deep,
21
+ But I have promises to keep,
22
+ And miles to go before I sleep,
23
+ And miles to go before I sleep.
data/spec/fixtures/en.txt CHANGED
@@ -1 +1,23 @@
1
- Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean. A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth. Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum decided to leave for the far World of Grammar. The Big Oxmox advised her not to do so, because there were thousands of bad Commas, wild Question Marks and devious Semikoli, but the Little Blind Text didn’t listen. She packed her seven versalia, put her initial into the belt and made herself on the way. When she reached the first hills of the Italic Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane. Pityful a rethoric question ran over her cheek, then
1
+ Stopping by Woods on a Snowy Evening
2
+
3
+ By Robert Frost
4
+
5
+ Whose woods these are I think I know.
6
+ His house is in the village though;
7
+ He will not see me stopping here
8
+ To watch his woods fill up with snow.
9
+
10
+ My little horse must think it queer
11
+ To stop without a farmhouse near
12
+ Between the woods and frozen lake
13
+ The darkest evening of the year.
14
+
15
+ He gives his harness bells a shake
16
+ To ask if there is some mistake.
17
+ The only other sound’s the sweep
18
+ Of easy wind and downy flake.
19
+
20
+ The woods are lovely, dark and deep,
21
+ But I have promises to keep,
22
+ And miles to go before I sleep,
23
+ And miles to go before I sleep.
data/spec/fixtures/es.txt CHANGED
@@ -1 +1,21 @@
1
- Una mañana, tras un sueño intranquilo, Gregorio Samsa se despertó convertido en un monstruoso insecto. Estaba echado de espaldas sobre un duro caparazón y, al alzar la cabeza, vio su vientre convexo y oscuro, surcado por curvadas callosidades, sobre el que casi no se aguantaba la colcha, que estaba a punto de escurrirse hasta el suelo. Numerosas patas, penosamente delgadas en comparación con el grosor normal de sus piernas, se agitaban sin concierto. - ¿Qué me ha ocurrido? No estaba soñando. Su habitación, una habitación normal, aunque muy pequeña, tenía el aspecto habitual. Sobre la mesa había desparramado un muestrario de paños - Samsa era viajante de comercio-, y de la pared colgaba una estampa recientemente recortada de una revista ilustrada y puesta en un marco dorado. La estampa mostraba a una mujer tocada con un gorro de pieles, envuelta en una estola también de pieles, y que, muy erguida, esgrimía un amplio manguito, asimismo de piel, que ocultaba todo su antebrazo. Gregorio miró hacia la ventana; estaba nublado, y sobre el cinc del alféizar repiqueteaban las gotas de lluvia, lo que le hizo sentir una gran melancolía. «Bueno -pensó-; ¿y si siguiese durmiendo un rato y me olvidase de
1
+ Un alto en el bosque mientras nieva
2
+
3
+ De quién es este bosque, saber creo
4
+ -en el poblado su morada veo-
5
+ no habrá de sorprenderme contemplando
6
+ cubrir su bosque el invernal blanqueo.
7
+
8
+ Mi caballito se dirá extrañado
9
+ que, sin granja cercana, hemos parado
10
+ de este año en la tarde más oscura,
11
+ entre el bosque y el lago congelado.
12
+
13
+ Sacudiéndose, agita su cencerro
14
+ preguntando quizá: -¿será algún yerro?
15
+ Sólo el cierzo y los copos rumorean
16
+ blandamente del bosque en el encierro.
17
+
18
+ Yo, el bosque hondo y fusco veo risueño...
19
+ Mas, en cumplir promesas tengo empeño,
20
+ y millas debo andar antes del sueño,
21
+ un largo andar para llegar al sueño.
data/spec/fixtures/fr.txt CHANGED
@@ -1 +1,23 @@
1
- En se réveillant un matin après des rêves agités, Gregor Samsa se retrouva, dans son lit, métamorphosé en un monstrueux insecte. Il était sur le dos, un dos aussi dur qu’une carapace, et, en relevant un peu la tête, il vit, bombé, brun, cloisonné par des arceaux plus rigides, son abdomen sur le haut duquel la couverture, prête à glisser tout à fait, ne tenait plus qu’à peine. Ses nombreuses pattes, lamentablement grêles par comparaison avec la corpulence qu’il avait par ailleurs, grouillaient désespérément sous ses yeux.« Qu’est-ce qui m’est arrivé ? » pensa-t-il. Ce n’était pas un rêve. Sa chambre, une vraie chambre humaine, juste un peu trop petite, était là tranquille entre les quatre murs qu’il connaissait bien. Au-dessus de la table où était déballée une collection d’échantillons de tissus - Samsa était représentant de commerce - on voyait accrochée l’image qu’il avait récemment découpée dans un magazine et mise dans un joli cadre doré. Elle représentait une dame munie d’une toque et d’un boa tous les deux en fourrure et qui, assise bien droite, tendait vers le spectateur un lourd manchon de fourrure où tout son avant-bras avait disparu. Le regard de Gregor se tourna ensuite vers
1
+ En s'arrêtant par les bois un soir de neige
2
+
3
+ Auteur: Robert Frost
4
+
5
+ À qui sont ces bois, je crois que je sais.
6
+ Sa maison est au village pourtant ;
7
+ Il ne me verra pas m'arrêter ici
8
+ À regarder ses bois recouverts de neige.
9
+
10
+ Mon petit cheval doit trouver cela étrange
11
+ De s'arrêter loin de toute ferme aux alentours
12
+ Entre ces bois et ce lac gelé
13
+ Au soir le plus sombre de l'année.
14
+
15
+ Il fait tinter les clochettes de son harnais en tirant dessus
16
+ Comme pour demander s'il n'y a pas là quelque erreur.
17
+ Les seuls autres bruits le souffle
18
+ D'une brise légère et le son duveteux des flocons.
19
+
20
+ Les bois sont beaux, sombres et profonds,
21
+ Mais j'ai des promesses à tenir
22
+ Et un long chemin à parcourir avant de dormir,
23
+ Et un long chemin à parcourir avant de dormir.
data/spec/fixtures/ru.txt CHANGED
@@ -1 +1,21 @@
1
- Любя, съешь щипцы, вздохнёт мэр, — кайф жгуч. Шеф взъярён тчк щипцы с эхом гудбай Жюль. Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф. Экс-граф? Плюш изъят. Бьём чуждый цен хвощ! Эх, чужак! Общий съём цен шляп (юфть) — вдрызг! Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч. Шеф взъярён тчк щипцы с эхом гудбай Жюль. Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф. Экс-граф? Плюш изъят. Бьём чуждый цен хвощ! Эх, чужак! Общий съём цен шляп (юфть) — вдрызг! Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч. Шеф взъярён тчк щипцы с эхом гудбай Жюль. Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф. Экс-граф? Плюш изъят. Бьём чуждый цен хвощ! Эх, чужак! Общий съём цен шляп (юфть) — вдрызг! Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч. Шеф взъярён тчк щипцы с эхом гудбай Жюль. Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф. Экс-граф? Плюш изъят. Бьём чуждый цен хвощ! Эх, чужак! Общий съём цен шляп (юфть) — вдрызг!Любя, съешь щипцы, — вздохнёт мэр, — кайф жгуч. Шеф взъярён тчк щипцы с эхом гудбай Жюль. Эй, жлоб! Где туз? Прячь юных съёмщиц в шкаф. Экс-граф? Плюш изъят. Бьём чуждый цен
1
+ Остановившись у леса снежным вечером
2
+
3
+ Чей лес, мне кажется, я знаю:
4
+ в селе живет его хозяин.
5
+ Он не увидит, как на снежный
6
+ я лес его стою взираю.
7
+
8
+ В недоуменье конь, конечно,
9
+ зачем в ночи за год темнейшей
10
+ мы стали там, где нет жилья,
11
+ у леса с озером замерзшим.
12
+
13
+ Он, бубенцом слегка звеня,
14
+ как будто бы корит меня,
15
+ да веет слабый ветерок,
16
+ пушистым снегом шелестя.
17
+
18
+ Лес сладок, темен и глубок,
19
+ но в путь пора мне — долг есть долг.
20
+ И ехать долго — сон далек,
21
+ и ехать долго — сон далек.
@@ -0,0 +1 @@
1
+ hello
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ require 'rika/cli/args_parser'
6
+
7
+ describe ArgsParser do
8
+ let(:versions_regex) { /Versions:.*Rika: (\d+\.\d+\.\d+(-\w+)?).*Tika: (\d+\.\d+\.\d+(-\w+)?)/ }
9
+
10
+ specify 'returns a hash of options, a target array, and help text' do
11
+ options, targets, help_text = described_class.call([])
12
+ expect(options).to be_a(Hash)
13
+ expect(targets).to be_an(Array)
14
+ expect(help_text).to be_a(String)
15
+ end
16
+
17
+ context 'when parsing options' do
18
+ RSpec.shared_examples 'sets_options_correctly' do |args, option_key, expected_value|
19
+ specify "correctly sets #{option_key} to #{expected_value} when args are #{args}" do
20
+ options, _, _ = described_class.call(args)
21
+ expect(options[option_key]).to eq(expected_value)
22
+ end
23
+ end
24
+
25
+ # Test default option values:
26
+ include_examples('sets_options_correctly', [], :as_array, false)
27
+ include_examples('sets_options_correctly', [], :text, true)
28
+ include_examples('sets_options_correctly', [], :metadata, true)
29
+ include_examples('sets_options_correctly', [], :format, 'at')
30
+ include_examples('sets_options_correctly', [], :key_sort, true)
31
+ include_examples('sets_options_correctly', [], :source, true)
32
+
33
+ # Test -a as_array option:
34
+ include_examples('sets_options_correctly', %w[-a], :as_array, true)
35
+ include_examples('sets_options_correctly', %w[--as_array], :as_array, true)
36
+ include_examples('sets_options_correctly', %w[-a -a-], :as_array, false)
37
+ include_examples('sets_options_correctly', %w[--no-as_array], :as_array, false)
38
+
39
+ # Test -f format option:
40
+ include_examples('sets_options_correctly', %w[-fyy], :format, 'yy')
41
+ include_examples('sets_options_correctly', %w[--format yy], :format, 'yy')
42
+ include_examples('sets_options_correctly', %w[-f yy], :format, 'yy')
43
+ include_examples('sets_options_correctly', %w[-f y], :format, 'yy')
44
+ include_examples('sets_options_correctly', %w[-f yj], :format, 'yj')
45
+ include_examples('sets_options_correctly', %w[-f yjJ], :format, 'yj') # Test extra characters after valid format
46
+
47
+ # Test -m metadata option:
48
+ include_examples('sets_options_correctly', %w[-m- -m], :metadata, true)
49
+ include_examples('sets_options_correctly', %w[-m- -m+], :metadata, true)
50
+ include_examples('sets_options_correctly', %w[--metadata false --metadata], :metadata, true)
51
+ include_examples('sets_options_correctly', %w[-m -m-], :metadata, false)
52
+ include_examples('sets_options_correctly', %w[-m yes], :metadata, true)
53
+ include_examples('sets_options_correctly', %w[-m no], :metadata, false)
54
+ include_examples('sets_options_correctly', %w[-m true], :metadata, true)
55
+ include_examples('sets_options_correctly', %w[-m false], :metadata, false)
56
+ include_examples('sets_options_correctly', %w[--metadata false], :metadata, false)
57
+ include_examples('sets_options_correctly', %w[--no-metadata], :metadata, false)
58
+
59
+ # Test -t text option:
60
+ include_examples('sets_options_correctly', %w[-t], :text, true)
61
+ include_examples('sets_options_correctly', %w[-t -t-], :text, false)
62
+ include_examples('sets_options_correctly', %w[-t yes], :text, true)
63
+ include_examples('sets_options_correctly', %w[-t no], :text, false)
64
+ include_examples('sets_options_correctly', %w[-t true], :text, true)
65
+ include_examples('sets_options_correctly', %w[-t false], :text, false)
66
+ include_examples('sets_options_correctly', %w[--text false], :text, false)
67
+ include_examples('sets_options_correctly', %w[--text false --text], :text, true)
68
+
69
+ # Test -k key sort option:
70
+ include_examples('sets_options_correctly', %w[-k-], :key_sort, false)
71
+
72
+ # Test -s source option:
73
+ include_examples('sets_options_correctly', %w[-s-], :source, false)
74
+ end
75
+
76
+ describe '#versions_string' do
77
+ specify 'returns a Rika version and a Tika version' do
78
+ expect(described_class.new.send(:versions_string)).to match(versions_regex)
79
+ end
80
+ end
81
+
82
+ context 'when processing environment variables' do
83
+ it 'adds arguments from the environment to the args list' do
84
+ args_parser = described_class.new
85
+ allow(args_parser).to receive(:environment_options).and_return('-t-')
86
+ options, _, _ = args_parser.call([])
87
+ expect(options[:text]).to be(false)
88
+ end
89
+
90
+ it 'overrides environment variable options with command line options' do
91
+ env_format_arg = '-fyy'
92
+ cmd_line_format = 'JJ'
93
+ cmd_line_args = ["-f#{cmd_line_format}"]
94
+ args_parser = described_class.new
95
+ allow(args_parser).to receive(:environment_options).and_return(env_format_arg)
96
+ options, _, _ = args_parser.call(cmd_line_args)
97
+ expect(options[:format]).to eq(cmd_line_format)
98
+ end
99
+ end
100
+
101
+ describe 'DEFAULT_OPTIONS hash' do
102
+ specify 'has the correct default values' do
103
+ expect(described_class::DEFAULT_OPTIONS).to eq(
104
+ as_array: false,
105
+ text: true,
106
+ metadata: true,
107
+ format: 'at',
108
+ key_sort: true,
109
+ source: true
110
+ )
111
+ end
112
+
113
+ specify 'is frozen' do
114
+ expect(described_class::DEFAULT_OPTIONS).to be_frozen
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'rika/cli/rika_command'
5
+
6
+ RF = Rika::Formatters
7
+
8
+ describe RikaCommand do
9
+ let(:versions_regex) { /Versions:.*Rika: (\d+\.\d+\.\d+(-\w+)?).*Tika: (\d+\.\d+\.\d+(-\w+)?)/ }
10
+
11
+ before do
12
+ @original_stdout = $stdout
13
+ @original_stderr = $stderr
14
+ $stdout = StringIO.new
15
+ $stderr = StringIO.new
16
+ end
17
+
18
+ after do
19
+ $stdout = @original_stdout
20
+ $stderr = @original_stderr
21
+ end
22
+
23
+ describe '#call' do
24
+ specify 'call should run the command without error' do
25
+ expect { described_class.new([fixture_path('tiny.txt')]).call }.not_to raise_error
26
+ end
27
+
28
+ specify 'prints version and exits when -v or --version is specified' do
29
+ expect { described_class.new(%w[-v]).call }.to output(versions_regex).to_stdout.and raise_error(SystemExit)
30
+ end
31
+
32
+ specify 'prints help and exits when -h or --help is specified' do
33
+ regex = /Usage: rika \[options\] <file or url> /m
34
+ expect { described_class.new(%w[-h]).call }.to output(regex).to_stdout.and raise_error(SystemExit)
35
+ end
36
+
37
+ specify 'when run in array mode, outputs the string representation of an array of parse results' do
38
+ original_stdout = $stdout
39
+ $stdout = StringIO.new
40
+ begin
41
+ tiny_filespec = fixture_path('tiny.txt')
42
+ args = ['-a', '-fJ', tiny_filespec, tiny_filespec]
43
+ described_class.new(args).call
44
+ output = $stdout.string
45
+ object = JSON.parse(output)
46
+ expect(object).to be_an(Array)
47
+ expect(object.size).to eq(2)
48
+ expect(object.map(&:class)).to eq([Hash, Hash])
49
+ ensure
50
+ $stdout = original_stdout
51
+ end
52
+ end
53
+ end
54
+
55
+ describe '#single_document_output' do
56
+ RSpec.shared_examples 'verify_result_is_hash' do |format_chars, parser|
57
+ specify "correctly uses result hash for JSON and YAML when options are #{format_chars}" do
58
+ original_stdout = $stdout
59
+ $stdout = StringIO.new
60
+ begin
61
+ rika_command = described_class.new(["-f#{format_chars}", fixture_path('tiny.txt')])
62
+ rika_command.call
63
+ output = $stdout.string
64
+ warn output
65
+ result_hash = parser.call(output)
66
+ expect(result_hash).to be_a(Hash)
67
+ expect(result_hash['metadata']).to be_a(Hash)
68
+ expect(result_hash['text']).to be_a(String)
69
+ ensure
70
+ $stdout = original_stdout
71
+ end
72
+ end
73
+ end
74
+
75
+ include_examples('verify_result_is_hash', 'JJ', ->(s) { JSON.parse(s) })
76
+ include_examples('verify_result_is_hash', 'jj', ->(s) { JSON.parse(s) })
77
+ include_examples('verify_result_is_hash', 'yy', ->(s) { YAML.safe_load(s) })
78
+ end
79
+
80
+ describe '#set_output_formats' do
81
+ RSpec.shared_examples 'verify_correct_output_formats_selected' \
82
+ do |format_chars, expected_m_formatter, expected_t_formatter|
83
+ specify "correctly sets output formats when options are #{format_chars}" do
84
+ rika_command = described_class.new(["-f#{format_chars}"])
85
+ rika_command.send(:prepare)
86
+ expect(rika_command.send(:metadata_formatter)).to eq(expected_m_formatter)
87
+ expect(rika_command.send(:text_formatter)).to eq(expected_t_formatter)
88
+ end
89
+ end
90
+
91
+ include_examples('verify_correct_output_formats_selected', 'aj', RF::AWESOME_PRINT_FORMATTER, RF::JSON_FORMATTER)
92
+ include_examples('verify_correct_output_formats_selected', 'Jy', RF::PRETTY_JSON_FORMATTER, RF::YAML_FORMATTER)
93
+ include_examples('verify_correct_output_formats_selected', 'ti', RF::TO_S_FORMATTER, RF::INSPECT_FORMATTER)
94
+
95
+ RSpec.shared_examples 'verify_bad_output_format_exits' do |format_chars|
96
+ specify "exits when a bad output format is specified with #{format_chars}" do
97
+ expect { described_class.new(["-f#{format_chars}"]).call }.to raise_error(SystemExit)
98
+ end
99
+ end
100
+
101
+ include_examples 'verify_bad_output_format_exits', 'ax'
102
+ include_examples 'verify_bad_output_format_exits', 'xa'
103
+ include_examples 'verify_bad_output_format_exits', 'x'
104
+ end
105
+
106
+ describe '#warn_if_no_targets_specified' do
107
+ it 'prints a warning if no targets are specified' do
108
+ rika_command = described_class.new([])
109
+ allow(rika_command).to receive_messages(
110
+ targets: [],
111
+ help_text: 'sample help text'
112
+ )
113
+ expect { rika_command.send(:report_and_exit_if_no_targets_specified) }.to raise_error(SystemExit)
114
+ expect(rika_command).to have_received(:help_text).once
115
+ output = $stderr.string
116
+ expect(output).to match(/No targets specified/)
117
+ expect(output).to include('sample help text')
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'rika/formatters'
5
+
6
+ describe Rika::Formatters do
7
+ describe '.get' do
8
+ let(:rf) { described_class }
9
+
10
+ it 'returns the correct formatter for each option character' do
11
+ expect(rf.get('a')).to eq(rf::AWESOME_PRINT_FORMATTER)
12
+ expect(rf.get('i')).to eq(rf::INSPECT_FORMATTER)
13
+ expect(rf.get('j')).to eq(rf::JSON_FORMATTER)
14
+ expect(rf.get('J')).to eq(rf::PRETTY_JSON_FORMATTER)
15
+ expect(rf.get('t')).to eq(rf::TO_S_FORMATTER)
16
+ expect(rf.get('y')).to eq(rf::YAML_FORMATTER)
17
+ end
18
+
19
+ it 'raises an error if the option character is invalid' do
20
+ expect { rf.get('x') }.to raise_error(KeyError)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'rika/parse_result'
5
+
6
+ describe Rika::ParseResult do
7
+ context 'when initialized' do
8
+ specify 'contains the necessary fields' do
9
+ expect(described_class.new).to respond_to(
10
+ :content,
11
+ :text, # alias for content
12
+ :metadata,
13
+ :metadata_java,
14
+ :content_type,
15
+ :language,
16
+ :input_type,
17
+ :data_source,
18
+ :max_content_length
19
+ )
20
+ end
21
+ end
22
+
23
+ describe '#file?' do
24
+ specify 'returns true if input_type is :file' do
25
+ expect(described_class.new(input_type: :file).file?).to be true
26
+ end
27
+
28
+ specify 'returns false if input_type is not :file' do
29
+ expect(described_class.new.file?).to be false
30
+ end
31
+ end
32
+
33
+ describe '#http?' do
34
+ specify 'returns true if input_type is :http' do
35
+ expect(described_class.new(input_type: :http).http?).to be true
36
+ end
37
+
38
+ specify 'returns false if input_type is not :http' do
39
+ expect(described_class.new.http?).to be false
40
+ end
41
+ end
42
+ end