Class: LingotekClient::Resource::Project

Inherits:
Base
  • Object
show all
Defined in:
lib/lingotek-client/resource/project.rb

Constant Summary collapse

FILENAME =
'download.zip'
ACTIVE =
'Active'
COMPLETED =
'Completed'

Constants inherited from Base

Base::ERRORS, Base::FAIL, Base::RESULTS

Instance Attribute Summary collapse

Attributes inherited from Base

#data

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

all, find, key

Constructor Details

#initialize(attrs) ⇒ Project

Returns a new instance of Project.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/lingotek-client/resource/project.rb', line 11

def initialize(attrs)
  super(attrs)
  @id = attrs['id']
  @name = attrs['name']
  @state = attrs['state']
  @company_id = attrs['companyId']
  @percent_complete = attrs['percentComplete']
  @document_ids = attrs['documents'].map { |doc| doc['id'] }
  @created_at = attrs['createdDate']
  @workflow_id = attrs['workflowId']
  @due_date = attrs['due_date']
end

Instance Attribute Details

#company_idObject

Returns the value of attribute company_id.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def company_id
  @company_id
end

#created_atObject

Returns the value of attribute created_at.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def created_at
  @created_at
end

#document_idsObject

Returns the value of attribute document_ids.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def document_ids
  @document_ids
end

#due_dateObject

Returns the value of attribute due_date.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def due_date
  @due_date
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def id
  @id
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def name
  @name
end

#percent_completeObject

Returns the value of attribute percent_complete.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def percent_complete
  @percent_complete
end

#stateObject

Returns the value of attribute state.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def state
  @state
end

#workflow_idObject

Returns the value of attribute workflow_id.



4
5
6
# File 'lib/lingotek-client/resource/project.rb', line 4

def workflow_id
  @workflow_id
end

Class Method Details

.download_documents(id, target) ⇒ Object



32
33
34
35
36
37
# File 'lib/lingotek-client/resource/project.rb', line 32

def self.download_documents(id, target)
  FileUtils.mkdir_p("#{target}/#{id}")
  File.open(FILENAME, 'wa') do |f|
    f.write(Lingotek::API::api.downloadProjectDocuments projectId: id)
  end
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/lingotek-client/resource/project.rb', line 39

def active?
  @state == ACTIVE
end

#completed?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/lingotek-client/resource/project.rb', line 43

def completed?
  @state == COMPLETED
end

#documentsObject



28
29
30
# File 'lib/lingotek-client/resource/project.rb', line 28

def documents
  @document_ids.map { |doc_id| Lingotek::API::Document.find(doc_id) }
end

#workflowObject



24
25
26
# File 'lib/lingotek-client/resource/project.rb', line 24

def workflow
  @workflow ||= Lingotek::API::Workflow.find @workflow_id if @workflow_id && @workflow_id != 0
end