mhtml 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: e6c8f08f08cddf731523a803d8ff1fd6237248cc
4
- data.tar.gz: 5d529f065c8c1c1adaa0656c16ba95cf785b8e45
3
+ metadata.gz: 60fd056e7a5ded9db6a7e18e49c982100672e084
4
+ data.tar.gz: 1236377e35f0c3176bcaa25aaa6db13757d64d63
5
5
  SHA512:
6
- metadata.gz: 8fbfe9a3c36c375f8493ce8df95134123edf4353447fda375be7a95ce367905c6631cbf10f8d599a5405421bf6b3040af1eea66affb227f45543d35f618adccb
7
- data.tar.gz: bd81a7aa328a18d3437e3feeaedfdccea463ae0f9e683986c92fc637cc962877efca8d4a7e4fa8c9d31480e1b27d34760f5ab39de3a13793f3c46f999c1e1d3b
6
+ metadata.gz: 9cb37bbcc90d6e0c7658cde28c89bc69e2d79315709f6d86c8ac941c3284471e7ef0d7d7c25d04f0a8cb8a33ffe79b56216d2b09a5b4bc8a75eb16b7e4caace7
7
+ data.tar.gz: '095474af649049223490a686331be4368b6956c6f0281985436c4815f91fb9ddcbd92905c1c0c86af731801bfefd5de988efccbfa60427775a1bb2a9524a02f7'
@@ -3,7 +3,13 @@ require 'http-parser'
3
3
  module Mhtml
4
4
  class Document
5
5
  attr_reader :chunked, :parser
6
- attr_accessor :headers, :body, :is_quoted_printable, :encoding
6
+
7
+ attr_accessor :headers,
8
+ :body,
9
+ :is_quoted_printable,
10
+ :encoding,
11
+ :file_path,
12
+ :root_doc
7
13
 
8
14
  def initialize(str = nil)
9
15
  @chunked = !str.is_a?(String)
@@ -61,6 +67,23 @@ module Mhtml
61
67
  header
62
68
  end
63
69
 
70
+ def relative_file_path
71
+ return nil if @file_path.nil?
72
+ return @file_path if @root_doc.nil? || @root_doc.file_path.nil?
73
+ return '.' if @file_path == @root_doc.file_path
74
+
75
+ str = nil
76
+ if @file_path.start_with?(@root_doc.file_path)
77
+ start = @root_doc.file_path.length
78
+ str = @file_path[start..@file_path.length - 1]
79
+ else
80
+ str = @file_path
81
+ end
82
+
83
+ str = str[1..(str.length - 1)] if str[0] == '/'
84
+ str
85
+ end
86
+
64
87
  # for testing only = no spec implemented
65
88
  def to_s
66
89
  @headers.join(LINE_BREAK) + Mhtml::DOUBLE_LINE_BREAK + @body
@@ -117,6 +140,10 @@ module Mhtml
117
140
  if !value.nil? && value.value == 'quoted-printable'
118
141
  @is_quoted_printable = true
119
142
  end
143
+
144
+ elsif header.key == 'Content-Location'
145
+ value = header.values.first
146
+ @file_path = value.value unless value.nil?
120
147
  end
121
148
 
122
149
  @headers_proc.call(header) unless @headers_proc.nil?
@@ -71,7 +71,9 @@ module Mhtml
71
71
  is_last_part = i + 1 == parts.length
72
72
  handle_chunked_body(part, is_last_part, is_last_subdoc)
73
73
  else
74
- @sub_docs << Document.new(part)
74
+ sub_doc = Document.new(part)
75
+ sub_doc.root_doc = self
76
+ @sub_docs << sub_doc
75
77
  end
76
78
  end
77
79
  end
@@ -110,6 +112,7 @@ module Mhtml
110
112
 
111
113
  def create_chunked_subdoc
112
114
  @chunked_sub_doc = Document.new
115
+ @chunked_sub_doc.root_doc = self
113
116
 
114
117
  @chunked_sub_doc.on_header do |header|
115
118
  @subdoc_header_proc.call(header) unless @subdoc_header_proc.nil?
data/lib/mhtml/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mhtml
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mhtml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Williams