Class: Gitlab::GithubImport::Markdown::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/github_import/markdown/attachment.rb

Constant Summary collapse

MEDIA_TYPES =
%w[gif jpeg jpg mov mp4 png svg webm].freeze
DOC_TYPES =
%w[
  csv docx fodg fodp fods fodt gz log md odf odg odp ods
  odt pdf pptx tgz txt xls xlsx zip
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url) ⇒ Attachment

Returns a new instance of Attachment.



81
82
83
84
# File 'lib/gitlab/github_import/markdown/attachment.rb', line 81

def initialize(name, url)
  @name = name
  @url = url
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



79
80
81
# File 'lib/gitlab/github_import/markdown/attachment.rb', line 79

def name
  @name
end

#urlObject (readonly)

Returns the value of attribute url.



79
80
81
# File 'lib/gitlab/github_import/markdown/attachment.rb', line 79

def url
  @url
end

Class Method Details

.from_markdown(markdown_node) ⇒ Object

markdown_node - CommonMarker::Node



15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab/github_import/markdown/attachment.rb', line 15

def from_markdown(markdown_node)
  case markdown_node.type
  when :html, :inline_html
    from_inline_html(markdown_node)
  when :image
    from_markdown_image(markdown_node)
  when :link
    from_markdown_link(markdown_node)
  end
end

Instance Method Details

#doc_belongs_to_project?(import_source) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/gitlab/github_import/markdown/attachment.rb', line 92

def doc_belongs_to_project?(import_source)
  url.start_with?(
    "#{::Gitlab::GithubImport::MarkdownText.github_url}/#{import_source}/files"
  )
end

#inspectObject



105
106
107
# File 'lib/gitlab/github_import/markdown/attachment.rb', line 105

def inspect
  "<#{self.class.name}: { name: #{name}, url: #{url} }>"
end

#media?(import_source) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
101
102
103
# File 'lib/gitlab/github_import/markdown/attachment.rb', line 98

def media?(import_source)
  url.start_with?(
    "#{::Gitlab::GithubImport::MarkdownText.github_url}/#{import_source}/assets",
    ::Gitlab::GithubImport::MarkdownText::GITHUB_MEDIA_CDN
  )
end

#part_of_project_blob?(import_source) ⇒ Boolean

Returns:

  • (Boolean)


86
87
88
89
90
# File 'lib/gitlab/github_import/markdown/attachment.rb', line 86

def part_of_project_blob?(import_source)
  url.start_with?(
    "#{::Gitlab::GithubImport::MarkdownText.github_url}/#{import_source}/blob"
  )
end