string_serve 1.0.0
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 +7 -0
- data/lib/string_serve.rb +35 -0
- metadata +44 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 164a28990398cf13bf695171c7404d7c4c6e208e
|
4
|
+
data.tar.gz: ea0ae879e328ccfdf7f7806d86f384b73702a442
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6f8b59f4bb0438d0aa0922ed2e44dd51cde47a2a4c9bd77fe24205229339e0b096886f4ba892c7f1cb4450a0ea5e637f8b1813501bbb56a8c2bbf26d09357f0
|
7
|
+
data.tar.gz: f039dce3ecdf35a88a39ac5ff2d1141bf34974d2897a2b25230cd04d3892b8b3206f368553d9234bc06c3ada7ccd59543463977a057584cb7a97c9e35a54c2f6
|
data/lib/string_serve.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'w3c_validators'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
class String
|
6
|
+
def serve
|
7
|
+
Rack::Handler::WEBrick.run(->(env) {
|
8
|
+
[200, {'Content-Type' => content_type}, [self]]
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def content_type
|
15
|
+
case
|
16
|
+
when valid_html?
|
17
|
+
'text/html'
|
18
|
+
when valid_json?
|
19
|
+
'application/json'
|
20
|
+
else
|
21
|
+
'text/plain'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def valid_json?
|
26
|
+
!!JSON.parse(self) rescue false
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_html?
|
30
|
+
W3CValidators::MarkupValidator.new
|
31
|
+
.validate_text(self)
|
32
|
+
.errors
|
33
|
+
.length == 0
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: string_serve
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dennis Heckman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: String to website converter
|
14
|
+
email: denheck@gmail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/string_serve.rb
|
20
|
+
homepage: http://rubygems.org/gems/string_serve
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubyforge_project:
|
40
|
+
rubygems_version: 2.4.5.1
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: String Server
|
44
|
+
test_files: []
|